Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove an unnecessary dependency #458

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const {ReadableWebToNodeStream} = require('readable-web-to-node-stream');
const toBuffer = require('typedarray-to-buffer');
const core = require('./core');

async function fromStream(stream) {
Expand All @@ -11,25 +10,25 @@ async function fromStream(stream) {
}

async function fromBlob(blob) {
const buffer = await convertBlobToBuffer(blob);
const buffer = await convertBlobToBuffer(blob).then(Buffer.from);
jimmywarting marked this conversation as resolved.
Show resolved Hide resolved
return core.fromBuffer(buffer);
}

/**
Convert Web API File to Node Buffer.
@param {Blob} blob - Web API Blob.
@returns {Promise<Buffer>}
@returns {Promise<ArrayBuffer>}
*/
function convertBlobToBuffer(blob) {
if (blob.arrayBuffer) {
return blob.arrayBuffer();
}

// TODO: Remove when stop supporting older environments
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.addEventListener('loadend', event => {
let data = event.target.result;
if (data instanceof ArrayBuffer) {
data = toBuffer(new Uint8Array(event.target.result));
}

resolve(data);
resolve(event.target.result);
});

fileReader.addEventListener('error', event => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@
"dependencies": {
"readable-web-to-node-stream": "^3.0.0",
"strtok3": "^6.0.3",
"token-types": "^2.0.0",
"typedarray-to-buffer": "^3.1.5"
"token-types": "^2.0.0"
},
"xo": {
"envs": [
Expand Down