Skip to content

Instantly share code, notes, and snippets.

@ashelley
Created August 13, 2014 20:03
Show Gist options
  • Save ashelley/6cbad3f489499996a95e to your computer and use it in GitHub Desktop.
Save ashelley/6cbad3f489499996a95e to your computer and use it in GitHub Desktop.
pdfkit compression performance workaround for this problem https://github.com/joyent/node/issues/6623#issuecomment-52064608
diff --git a/lib/reference.coffee b/lib/reference.coffee
index 9e961d6..b98a868 100644
--- a/lib/reference.coffee
+++ b/lib/reference.coffee
@@ -12,6 +12,7 @@ class PDFReference
@compress = @document.compress and not @data.Filter
@uncompressedLength = 0
@chunks = []
+ @chunksToCompress = [];
initDeflate: ->
@data.Filter = 'FlateDecode'
@@ -32,7 +33,7 @@ class PDFReference
if @compress
@initDeflate() if not @deflate
- @deflate.write chunk
+ @chunksToCompress.push(chunk);
else
@chunks.push chunk
@data.Length += chunk.length
@@ -42,6 +43,7 @@ class PDFReference
@write chunk
if @deflate
+ @deflate.write(Buffer.concat(@chunksToCompress));
@deflate.end()
else
@finalize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment