incalculable-garage-67131
08/04/2023, 6:26 PMvar jsonAsset = new pulumi.asset.StringAsset(`{"msg":"hello world"}\n`);
this.jsonGZipFile = new gcp.storage.BucketObject(
'myfolder/json-template.log.gz',
{
name: 'myfolder/json-template.log.gz',
bucket: pulumi.interpolate`${args.bucket}`,
contentType: 'application/x-ndjson',
contentEncoding: 'gzip',
source: jsonAsset,
}
);
File is created, but its an empty zip file.source
property on the BuckObject.
I had hoped to keep it in memory. I used these functions and used fs.write
to create a valid ndjson gzip file.
createNDJSONBuffer(data: any[]): Buffer {
const ndjsonData = data.map(item => JSON.stringify(item)).join('\n');
return Buffer.from(ndjsonData);
}
compressToGzipBuffer(inputBuffer: Buffer): Promise<Buffer> {
return new Promise((resolve, reject) => {
zlib.gzip(inputBuffer, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
}