Skip to content

Commit

Permalink
feat: remove blob stream dependency (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura authored Jul 11, 2022
1 parent 4bb97c3 commit 9996158
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .changeset/soft-ladybugs-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@react-pdf/pdfkit': patch
'@react-pdf/renderer': patch
---

feat: remove blob stream dependency
1 change: 0 additions & 1 deletion packages/pdfkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"fontkit": "^2.0.2"
},
"devDependencies": {
"blob-stream": "^0.1.2",
"iconv-lite": "^0.4.13"
}
}
1 change: 0 additions & 1 deletion packages/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@react-pdf/primitives": "^3.0.0",
"@react-pdf/render": "^3.2.0",
"@react-pdf/types": "^2.1.0",
"blob-stream": "^0.1.3",
"queue": "^6.0.1",
"react-reconciler": "^0.23.0",
"scheduler": "^0.17.0"
Expand Down
15 changes: 9 additions & 6 deletions packages/renderer/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import BlobStream from 'blob-stream';
import FontStore from '@react-pdf/font';
import renderPDF from '@react-pdf/render';
import PDFDocument from '@react-pdf/pdfkit';
Expand Down Expand Up @@ -58,21 +57,25 @@ const pdf = initialValue => {
};

const toBlob = async () => {
const chunks = [];
const instance = await render();
const stream = instance.pipe(BlobStream());

return new Promise((resolve, reject) => {
stream.on('finish', () => {
instance.on('data', chunk => {
chunks.push(
chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk),
);
});

instance.on('end', () => {
try {
const blob = stream.toBlob('application/pdf');
const blob = new Blob(chunks, { type: 'application/pdf' });
callOnRender({ blob });
resolve(blob);
} catch (error) {
reject(error);
}
});

stream.on('error', reject);
});
};

Expand Down
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3317,18 +3317,6 @@ bl@^4.0.3:
inherits "^2.0.4"
readable-stream "^3.4.0"

blob-stream@^0.1.2, blob-stream@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/blob-stream/-/blob-stream-0.1.3.tgz#98d668af6996e0f32ef666d06e215ccc7d77686c"
integrity sha1-mNZor2mW4PMu9mbQbiFczH13aGw=
dependencies:
blob "0.0.4"

blob@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.4.tgz#bcf13052ca54463f30f9fc7e95b9a47630a94921"
integrity sha1-vPEwUspURj8w+fx+lbmkdjCpSSE=

bluebird@^3.5.1, bluebird@^3.5.3, bluebird@^3.5.5:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
Expand Down

0 comments on commit 9996158

Please sign in to comment.