diff --git a/src/file.ts b/src/file.ts index 1df546b93..e00a8829a 100644 --- a/src/file.ts +++ b/src/file.ts @@ -2032,6 +2032,16 @@ class File extends ServiceObject { emitStream.write(chunk, encoding, cb); }, }); + // If the write stream, which is returned to the caller, catches an error we need to make sure that + // at least one of the streams in the pipeline below gets notified so that they + // all get cleaned up / destroyed. + writeStream.once('error', e => { + emitStream.destroy(e); + }); + // If the write stream is closed, cleanup the pipeline below by calling destroy on one of the streams. + writeStream.once('close', () => { + emitStream.destroy(); + }); const transformStreams: Transform[] = []; diff --git a/src/nodejs-common/service.ts b/src/nodejs-common/service.ts index 0a3111667..8156cd176 100644 --- a/src/nodejs-common/service.ts +++ b/src/nodejs-common/service.ts @@ -271,9 +271,8 @@ export class Service { }; if (reqOpts[GCCL_GCS_CMD_KEY]) { - reqOpts.headers[ - 'x-goog-api-client' - ] += ` gccl-gcs-cmd/${reqOpts[GCCL_GCS_CMD_KEY]}`; + reqOpts.headers['x-goog-api-client'] += + ` gccl-gcs-cmd/${reqOpts[GCCL_GCS_CMD_KEY]}`; } if (reqOpts.shouldReturnStream) { diff --git a/src/resumable-upload.ts b/src/resumable-upload.ts index 049e20c43..5a1f71ccc 100644 --- a/src/resumable-upload.ts +++ b/src/resumable-upload.ts @@ -933,9 +933,8 @@ export class Upload extends Writable { // `Content-Length` for multiple chunk uploads is the size of the chunk, // not the overall object headers['Content-Length'] = bytesToUpload; - headers[ - 'Content-Range' - ] = `bytes ${this.offset}-${endingByte}/${totalObjectSize}`; + headers['Content-Range'] = + `bytes ${this.offset}-${endingByte}/${totalObjectSize}`; } else { headers['Content-Range'] = `bytes ${this.offset}-*/${this.contentLength}`; } diff --git a/src/transfer-manager.ts b/src/transfer-manager.ts index 37230389f..8b361b688 100644 --- a/src/transfer-manager.ts +++ b/src/transfer-manager.ts @@ -223,9 +223,8 @@ class XMLMultiPartUploadHelper implements MultiPartUploadHelper { // Prepend command feature to value, if not already there if (!value.includes(GCCL_GCS_CMD_FEATURE.UPLOAD_SHARDED)) { - headers[ - key - ] = `${value} gccl-gcs-cmd/${GCCL_GCS_CMD_FEATURE.UPLOAD_SHARDED}`; + headers[key] = + `${value} gccl-gcs-cmd/${GCCL_GCS_CMD_FEATURE.UPLOAD_SHARDED}`; } } else if (key.toLocaleLowerCase().trim() === 'user-agent') { userAgentFound = true;