incorporate ArrayBuffer base Dish type. Add global file shim to node index. Fix Buffer -> ArrayBuffer transformation

This commit is contained in:
d98762625 2019-04-04 16:29:34 +01:00
parent e4ee0fc397
commit af504891e4
6 changed files with 13 additions and 17 deletions

View file

@ -387,7 +387,7 @@ class Dish {
[Dish.BIG_NUMBER]: () => Promise.resolve(DishBigNumber.toArrayBuffer.bind(this)()),
[Dish.JSON]: () => Promise.resolve(DishJSON.toArrayBuffer.bind(this)()),
[Dish.FILE]: () => DishFile.toArrayBuffer.bind(this)(),
[Dish.LIST_FILE]: () => DishListFile.toArrayBuffer.bind(this)(),
[Dish.LIST_FILE]: () => Promise.resolve(DishListFile.toArrayBuffer.bind(this)()),
[Dish.BYTE_ARRAY]: () => Promise.resolve(DishByteArray.toArrayBuffer.bind(this)()),
},
node: {

View file

@ -94,7 +94,7 @@ class Utils {
const paddedBytes = new Array(numBytes);
paddedBytes.fill(padByte);
Array.prototype.map.call(arr, function(b, i) {
[...arr].forEach((b, i) => {
paddedBytes[i] = b;
});
@ -1033,8 +1033,10 @@ class Utils {
if (!Utils.isNode()) {
throw new TypeError("Browser environment cannot support readFileSync");
}
return file.data.buffer;
// Resist using node's Buffer.buffer here - this yields a 8192 length byteArray
// regardless of the length of the buffer.
const arrayBuffer = Uint8Array.from(file.data);
return arrayBuffer.buffer;
}

View file

@ -17,14 +17,7 @@ class DishListFile extends DishTranslationType {
*/
static toArrayBuffer() {
DishListFile.checkForValue(this.value);
if (Utils.isNode()) {
// TODO
this.value = [].concat.apply([], this.value.map(f => Utils.readFileSync(f)).map(b => Array.prototype.slice.call(b)));
} else {
return new Promise((resolve, reject) => {
resolve(DishListFile.concatenateTypedArrays(...this.value).buffer);
});
}
this.value = DishListFile.concatenateTypedArrays(...this.value).buffer;
}
/**