File shim now translates correctly

This commit is contained in:
d98762625 2019-03-14 16:33:09 +00:00
parent d080c5dd14
commit 2019ae43d7
7 changed files with 14 additions and 28 deletions

View file

@ -336,13 +336,11 @@ class Dish {
// Node environment => translate is sync
if (Utils.isNode()) {
console.log('Running in node');
this._toByteArray();
this._fromByteArray(toType, notUTF8);
// Browser environment => translate is async
} else {
console.log('Running in browser');
return new Promise((resolve, reject) => {
this._toByteArray()
.then(() => this.type = Dish.BYTE_ARRAY)

View file

@ -472,7 +472,6 @@ class Utils {
const str = Utils.byteArrayToChars(byteArray);
try {
const utf8Str = utf8.decode(str);
if (str.length !== utf8Str.length) {
if (ENVIRONMENT_IS_WORKER()) {
self.setOption("attemptHighlight", false);
@ -966,12 +965,12 @@ class Utils {
if (!Utils.isNode()) {
throw new TypeError("Browser environment cannot support readFileSync");
}
let bytes = [];
for (const byte of file.data.values()) {
bytes = bytes.concat(byte);
}
console.log('readFileSync:');
console.log(file);
console.log(Buffer.from(file.data).toString());
return Buffer.from(file.data).buffer;
return bytes;
}

View file

@ -19,12 +19,7 @@ class DishFile extends DishTranslationType {
static toByteArray() {
DishFile.checkForValue(this.value);
if (Utils.isNode()) {
console.log('toByteArray original value:');
console.log(this.value);
// this.value = Utils.readFileSync(this.value);
this.value = Array.prototype.slice.call(Utils.readFileSync(this.value));
console.log('toByteArray value:');
console.log(this.value);
this.value = Utils.readFileSync(this.value);
} else {
return new Promise((resolve, reject) => {
Utils.readFile(this.value)
@ -42,9 +37,7 @@ class DishFile extends DishTranslationType {
*/
static fromByteArray() {
DishFile.checkForValue(this.value);
this.value = new File(this.value, "unknown");
console.log('from Byte array');
console.log(this.value);
this.value = new File(this.value, "file.txt");
}
}

View file

@ -17,10 +17,8 @@ class DishString extends DishTranslationType {
* convert the given value to a ByteArray
*/
static toByteArray() {
console.log('string to byte array');
DishString.checkForValue(this.value);
this.value = this.value ? Utils.strToByteArray(this.value) : [];
console.log(this.value);
}
/**

View file

@ -132,8 +132,6 @@ class Tar extends Operation {
tarball.writeBytes(input);
tarball.writeEndBlocks();
console.log('Tar bytes');
console.log(tarball.bytes);
return new File([new Uint8Array(tarball.bytes)], args[0]);
}