|
@@ -19,21 +19,21 @@ class File {
|
|
/**
|
|
/**
|
|
* Constructor
|
|
* Constructor
|
|
*
|
|
*
|
|
|
|
+ * https://w3c.github.io/FileAPI/#file-constructor
|
|
|
|
+ *
|
|
* @param {String|Array|ArrayBuffer|Buffer} bits - file content
|
|
* @param {String|Array|ArrayBuffer|Buffer} bits - file content
|
|
* @param {String} name (optional) - file name
|
|
* @param {String} name (optional) - file name
|
|
* @param {Object} stats (optional) - file stats e.g. lastModified
|
|
* @param {Object} stats (optional) - file stats e.g. lastModified
|
|
*/
|
|
*/
|
|
constructor(data, name="", stats={}) {
|
|
constructor(data, name="", stats={}) {
|
|
- // Look at File API definition to see how to handle this.
|
|
|
|
- this.data = Buffer.from(data[0]);
|
|
|
|
|
|
+ const buffers = data.map(d => Buffer.from(d));
|
|
|
|
+ const totalLength = buffers.reduce((p, c) => p + c.length, 0);
|
|
|
|
+ this.data = Buffer.concat(buffers, totalLength);
|
|
|
|
+
|
|
this.name = name;
|
|
this.name = name;
|
|
this.lastModified = stats.lastModified || Date.now();
|
|
this.lastModified = stats.lastModified || Date.now();
|
|
this.type = stats.type || mime.getType(this.name);
|
|
this.type = stats.type || mime.getType(this.name);
|
|
|
|
|
|
- console.log('File constructor');
|
|
|
|
- console.log(typeof data);
|
|
|
|
- console.log(data);
|
|
|
|
- console.log(this.data);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|