Per the issue I reported for Hummus.js: #342, I'm having trouble writing an appended PDF to Google Cloud Storage.
The simplest MWE, using Firebase functions, is:
const getRawBody = require('raw-body')
const admin = require('firebase-admin')
function asBuffer (filename) {
const bucket = admin.storage().bucket()
const file = bucket.file(filename)
return getRawBody(file.createReadStream())
}
function writePdf (buffer, writeStream) {
const pdfWriter = hummus.createWriter(
new hummus.PDFStreamForResponse(writeStream))
}
const rstream = new hummus.PDFRStreamForBuffer(buffer)
pdfWriter.appendPDFPagesFromPDF(rstream) // Memory error / timeout.
}
const buffer = asBuffer('gcs-path.pdf')
const file = bucket.file('new.pdf')
const fileOptions = {}
const writeStream = file.createWriteStream(fileOptions)
writePdf(buffer, writeStream)
Firebase functions consistently fails at appendPDFPagesFromPDF
with a memory limit error or timeout.
This workflow appears to be fine for other types of writeable streams (e.g. memorystream
and file streams).
This example could be made simpler by hard-coding a simple PDF, but it's worthwhile to note it since the issue at hand seems to be streaming related — and ideally this process could be simplified even further to remove the intermediate Buffer
conversion and switch to streams.