Skip to content

Commit 8e8036a

Browse files
committed
Allow TAR uploads to storage.
1 parent 2913444 commit 8e8036a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/gcp/storage.ts

Lines changed: 15 additions & 2 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;
@@ -252,6 +258,7 @@ export async function upload(
252258
};
253259
}
254260

261+
255262
/**
256263
* Uploads a zip file to the specified bucket using the firebasestorage api.
257264
*/
@@ -260,21 +267,27 @@ export async function uploadObject(
260267
source: { file: string; stream: Readable },
261268
/** Bucket to upload to. */
262269
bucketName: string,
270+
contentType?: ContentType,
263271
): Promise<{
264272
bucket: string;
265273
object: string;
266274
generation: string | null;
267275
}> {
268-
if (path.extname(source.file) !== ".zip") {
276+
if (contentType == ContentType.TAR) {
277+
if (path.extname(source.file) !== ".tar.gz") {
278+
throw new FirebaseError(`Expected a file name ending in .tar.gz, got ${source.file}`);
279+
}
280+
} else if (path.extname(source.file) !== ".zip") {
269281
throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
270282
}
283+
271284
const localAPIClient = new Client({ urlPrefix: storageOrigin() });
272285
const location = `/${bucketName}/${path.basename(source.file)}`;
273286
const res = await localAPIClient.request({
274287
method: "PUT",
275288
path: location,
276289
headers: {
277-
"Content-Type": "application/zip",
290+
"Content-Type": contentType == ContentType.TAR ? "application/octet-stream" : "application/zip",
278291
"x-goog-content-length-range": "0,123289600",
279292
},
280293
body: source.stream,

0 commit comments

Comments
 (0)