Hey all, I am attempting to merge n files of pdfs (up to 1000 at times) into a single pdf.The pdfs are stored on GoogleStorage and I have the option of getting the files in 1 of 3 ways.
Either a
Readable Stream
return this.storage.bucket(bucket).file(path).createReadStream();
Or a File object (a GCP class)
this.storage.bucket(bucket).file(path);
Or to simply download the files that actually returns a Promise<buffer>
readFile({ bucket, path }: BucketFileConfig): Promise<Buffer> {
const file = this.storage.bucket(bucket).file(path);
return new Promise((resolve, reject) => {
file.download((err, buffer) => {
if (err) {
this.logger.error(err, path);
reject(err);
} else {
resolve(buffer);
}
});
});
}
The thing is the third options does not seem feasible with 1000+ pdfs, I inted on using a package called pdf-lib to merge all the pdfs afterwards, and the issue is it only accepts buffer or read local files. What would be an ideal way to deal with an issue like this, do I simply go for the third options or is there something I'm missing here ? Any help is much appreciated!
What I have tried:
All attempt are in problem description