Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadDataDir option throws error for gzip file #402

Open
davepar opened this issue Oct 21, 2024 · 3 comments
Open

loadDataDir option throws error for gzip file #402

davepar opened this issue Oct 21, 2024 · 3 comments

Comments

@davepar
Copy link

davepar commented Oct 21, 2024

In Node v22, when I try to load an in memory database with {loadDataDir: <myfile.gzip>) where the file is a gzip file created from .dumpDataDir('gzip'), I get Error: File is corrupted.

When I unzip the file on the command line into a directory, and then load that directory with loadDataDir, it works fine.

If that's a known limitation, it would be nice to have it documented. Thanks!

To reproduce:

const db = new PGlite({ dataDir: databaseFilename, extensions: { cube, earthdistance } });
await db.waitReady;
// Add some tables and records
const savedDb = await db.dumpDataDir('gzip');  // Using 'none' instead works fine
writeFileSync(archiveFilename, Buffer.from(await savedDb.arrayBuffer()));
db.close();

And then:

const loadDataDir = new Blob([readFileSync(archiveFilename)]);
const db = new PGlite({ loadDataDir, extensions: { cube, earthdistance } });
@samwillis
Copy link
Collaborator

Thanks for the report. This isn't a know limitation, and as far as I'm aware should work.

@0xOlias
Copy link
Contributor

0xOlias commented Oct 21, 2024

Reproduced with Node 18-22 and Bun

https://github.com/0xOlias/pglite-gzip-repro

@kevin-on
Copy link

I resolved this issue by using new Blob([fileBuffer], { type: 'application/x-gzip' }) to set the Blob type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants