diff options
author | ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> | 2022-07-04 02:08:03 +0300 |
---|---|---|
committer | ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> | 2022-07-04 02:08:03 +0300 |
commit | 9ea33c2c1cd3ea9fcfa66569a3fb94148afd9869 (patch) | |
tree | 9c261293c638170f349f24d42cb7610bffb41efc /lib/file.js | |
parent | 4be86f5151381b34820a9892d3179afe0176fbfb (diff) |
fix: dedupe packages
Diffstat (limited to 'lib/file.js')
-rw-r--r-- | lib/file.js | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/lib/file.js b/lib/file.js index c5e5f1e..5e37581 100644 --- a/lib/file.js +++ b/lib/file.js @@ -2,8 +2,7 @@ const EventEmitter = require('events') const { PassThrough } = require('stream') const path = require('path') const render = require('render-media') -const streamToBlob = require('stream-to-blob') -const streamToBlobURL = require('stream-to-blob-url') +const { BlobWriteStream } = require('fast-blob-stream') const streamToBuffer = require('stream-with-known-length-to-buffer') const queueMicrotask = require('queue-microtask') const rangeParser = require('range-parser') @@ -123,20 +122,16 @@ class File extends EventEmitter { getBlob (cb) { if (typeof window === 'undefined') throw new Error('browser-only method') - streamToBlob(this.createReadStream(), this._getMimeType()) - .then( - blob => cb(null, blob), - err => cb(err) - ) + const writeStream = new BlobWriteStream(blob => { + cb(null, blob) + }, { mimeType: this._getMimeType() }) + this.createReadStream().pipe(writeStream) } getBlobURL (cb) { - if (typeof window === 'undefined') throw new Error('browser-only method') - streamToBlobURL(this.createReadStream(), this._getMimeType()) - .then( - blobUrl => cb(null, blobUrl), - err => cb(err) - ) + this.getBlob((_err, blob) => { + cb(null, URL.createObjectURL(blob)) + }) } appendTo (elem, opts, cb) { |