commit
This commit is contained in:
parent
70e2f7a8aa
commit
008d2f30d7
675 changed files with 189892 additions and 0 deletions
57
node_modules/fetch-blob/from.js
generated
vendored
Normal file
57
node_modules/fetch-blob/from.js
generated
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
const {statSync, createReadStream} = require('fs');
|
||||
const Blob = require('./index.js');
|
||||
const DOMException = require('domexception');
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @returns {Blob}
|
||||
*/
|
||||
function blobFrom(path) {
|
||||
const {size, mtime} = statSync(path);
|
||||
const blob = new BlobDataItem({path, size, mtime});
|
||||
|
||||
return new Blob([blob]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a blob backed up by a file on the disk
|
||||
* with minium requirement
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class BlobDataItem {
|
||||
constructor(options) {
|
||||
this.size = options.size;
|
||||
this.path = options.path;
|
||||
this.start = options.start;
|
||||
this.mtime = options.mtime;
|
||||
}
|
||||
|
||||
// Slicing arguments is first validated and formated
|
||||
// to not be out of range by Blob.prototype.slice
|
||||
slice(start, end) {
|
||||
return new BlobDataItem({
|
||||
path: this.path,
|
||||
start,
|
||||
mtime: this.mtime,
|
||||
size: end - start
|
||||
});
|
||||
}
|
||||
|
||||
stream() {
|
||||
if (statSync(this.path).mtime > this.mtime) {
|
||||
throw new DOMException('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError');
|
||||
}
|
||||
|
||||
return createReadStream(this.path, {
|
||||
start: this.start,
|
||||
end: this.start + this.size - 1
|
||||
});
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return 'Blob';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = blobFrom;
|
Loading…
Add table
Add a link
Reference in a new issue