mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Have output return a binary buffer
Right now output returns a string to its callback, this means you can't just write it to a file or send it to a response as the default encoding (utf8) is incorrect. You have to manually specify binary. If instead of a string you return a binary buffer then you don't have to worry about this. I also fixed the generation of the final string to not build the string with repeated concatenation which is O(n^2) and instead build up an array of strings then join them all at once which is O(n)
This commit is contained in:
parent
96bba3a035
commit
6e7b57a0d8
@ -98,11 +98,11 @@ class PDFDocument
|
||||
@generateXRef out
|
||||
@generateTrailer out
|
||||
|
||||
ret = ''
|
||||
ret = []
|
||||
for k in out
|
||||
ret += k + '\n'
|
||||
ret.push(k + '\n')
|
||||
|
||||
fn ret
|
||||
fn new Buffer(ret.join(''),'binary')
|
||||
|
||||
finalize: (fn) ->
|
||||
# convert strings in the info dictionary to literals
|
||||
@ -168,4 +168,4 @@ class PDFDocument
|
||||
toString: ->
|
||||
"[object PDFDocument]"
|
||||
|
||||
module.exports = PDFDocument
|
||||
module.exports = PDFDocument
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user