diff --git a/packages/pglite/src/fs/tarUtils.ts b/packages/pglite/src/fs/tarUtils.ts index 0c80d43e3..a1d184ac0 100644 --- a/packages/pglite/src/fs/tarUtils.ts +++ b/packages/pglite/src/fs/tarUtils.ts @@ -2,13 +2,20 @@ import { tar, untar, type TarFile, REGTYPE, DIRTYPE } from "tinytar"; import { FS } from "../postgres.js"; import { PGDATA } from "./index.js"; -export async function dumpTar(FS: FS, dbname?: string): Promise { +export async function dumpTar(FS: FS, dbname?: string): Promise { const tarball = createTarball(FS, PGDATA); const [compressed, zipped] = await maybeZip(tarball); const filename = (dbname || "pgdata") + (zipped ? ".tar.gz" : ".tar"); - return new File([compressed], filename, { - type: zipped ? "application/x-gtar" : "application/x-tar", - }); + const type = zipped ? "application/x-gzip" : "application/x-tar"; + if (typeof File !== "undefined") { + return new File([compressed], filename, { + type, + }); + } else { + return new Blob([compressed], { + type, + }); + } } const compressedMimeTypes = [ diff --git a/packages/pglite/src/fs/types.ts b/packages/pglite/src/fs/types.ts index ed09167d9..c3b6f0a7f 100644 --- a/packages/pglite/src/fs/types.ts +++ b/packages/pglite/src/fs/types.ts @@ -25,7 +25,7 @@ export interface Filesystem { /** * Dump the PGDATA dir from the filesystem to a gziped tarball. */ - dumpTar(FS: FS, dbname: string): Promise; + dumpTar(FS: FS, dbname: string): Promise; } export abstract class FilesystemBase implements Filesystem { @@ -38,5 +38,5 @@ export abstract class FilesystemBase implements Filesystem { ): Promise>; async syncToFs(FS: FS) {} async initialSyncFs(mod: FS) {} - abstract dumpTar(mod: FS, dbname: string): Promise; + abstract dumpTar(mod: FS, dbname: string): Promise; } diff --git a/packages/pglite/src/interface.ts b/packages/pglite/src/interface.ts index 15f3c544a..c2fa79764 100644 --- a/packages/pglite/src/interface.ts +++ b/packages/pglite/src/interface.ts @@ -90,7 +90,7 @@ export type PGliteInterface = { callback: (channel: string, payload: string) => void, ): () => void; offNotification(callback: (channel: string, payload: string) => void): void; - dumpDataDir(): Promise; + dumpDataDir(): Promise; }; export type PGliteInterfaceExtensions = E extends Extensions diff --git a/packages/pglite/src/pglite.ts b/packages/pglite/src/pglite.ts index 1885d4824..679accf2b 100644 --- a/packages/pglite/src/pglite.ts +++ b/packages/pglite/src/pglite.ts @@ -747,6 +747,7 @@ export class PGlite implements PGliteInterface { /** * Dump the PGDATA dir from the filesystem to a gziped tarball. + * @returns The tarball as a File object where available, and fallback to a Blob */ async dumpDataDir() { let dbname = this.dataDir?.split("/").pop() ?? "pgdata";