Skip to content

Commit f31dddc

Browse files
annajowangandrewbrook
authored andcommitted
Allow TAR uploads to storage. (#9541)
* Allow TAR uploads to storage.
1 parent 214ee9e commit f31dddc

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/gcp/storage.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import { ensure } from "../ensureApiEnabled";
1111
import * as utils from "../utils";
1212
import { fieldMasks } from "./proto";
1313

14+
/** Content Type **/
15+
export enum ContentType {
16+
ZIP = "ZIP",
17+
TAR = "TAR",
18+
}
19+
1420
/** Bucket Interface */
1521
interface BucketResponse {
1622
kind: string;
@@ -253,28 +259,39 @@ export async function upload(
253259
}
254260

255261
/**
256-
* Uploads a zip file to the specified bucket using the firebasestorage api.
262+
* Uploads a zip or tar file to the specified bucket using the firebasestorage api.
257263
*/
258264
export async function uploadObject(
259265
/** Source with file (name) to upload, and stream of file. */
260266
source: { file: string; stream: Readable },
261267
/** Bucket to upload to. */
262268
bucketName: string,
269+
contentType?: ContentType,
263270
): Promise<{
264271
bucket: string;
265272
object: string;
266273
generation: string | null;
267274
}> {
268-
if (path.extname(source.file) !== ".zip") {
269-
throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
275+
switch (contentType) {
276+
case ContentType.TAR:
277+
if (!source.file.endsWith(".tar.gz")) {
278+
throw new FirebaseError(`Expected a file name ending in .tar.gz, got ${source.file}`);
279+
}
280+
break;
281+
default:
282+
if (path.extname(source.file) !== ".zip") {
283+
throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
284+
}
270285
}
286+
271287
const localAPIClient = new Client({ urlPrefix: storageOrigin() });
272288
const location = `/${bucketName}/${path.basename(source.file)}`;
273289
const res = await localAPIClient.request({
274290
method: "PUT",
275291
path: location,
276292
headers: {
277-
"Content-Type": "application/zip",
293+
"Content-Type":
294+
contentType === ContentType.TAR ? "application/octet-stream" : "application/zip",
278295
"x-goog-content-length-range": "0,123289600",
279296
},
280297
body: source.stream,

0 commit comments

Comments
 (0)