2019-03-01 17:02:21 +01:00
|
|
|
/**
|
|
|
|
* @author d98762625 [d98762625@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2019
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import DishTranslationType from "./DishTranslationType";
|
|
|
|
import Utils from "../Utils";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translation methods for file Dishes
|
|
|
|
*/
|
|
|
|
class DishFile extends DishTranslationType {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert the given value to a ByteArray
|
|
|
|
* @param {File} value
|
|
|
|
*/
|
|
|
|
static toByteArray() {
|
|
|
|
DishFile.checkForValue(this.value);
|
|
|
|
if (Utils.isNode()) {
|
2019-03-14 09:27:06 +01:00
|
|
|
console.log('toByteArray original value:');
|
2019-03-11 10:47:58 +01:00
|
|
|
console.log(this.value);
|
2019-03-14 09:27:06 +01:00
|
|
|
// this.value = Utils.readFileSync(this.value);
|
2019-03-01 17:02:21 +01:00
|
|
|
this.value = Array.prototype.slice.call(Utils.readFileSync(this.value));
|
2019-03-14 09:27:06 +01:00
|
|
|
console.log('toByteArray value:');
|
|
|
|
console.log(this.value);
|
2019-03-01 17:02:21 +01:00
|
|
|
} else {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Utils.readFile(this.value)
|
|
|
|
.then(v => this.value = Array.prototype.slice.call(v))
|
|
|
|
.then(resolve)
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert the given value from a ByteArray
|
|
|
|
* @param {ByteArray} value
|
|
|
|
* @param {function} byteArrayToStr
|
|
|
|
*/
|
|
|
|
static fromByteArray() {
|
|
|
|
DishFile.checkForValue(this.value);
|
|
|
|
this.value = new File(this.value, "unknown");
|
2019-03-14 09:27:06 +01:00
|
|
|
console.log('from Byte array');
|
|
|
|
console.log(this.value);
|
2019-03-01 17:02:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DishFile;
|