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

TypeError on trying to .load() a stream from .dump(); only imports 400 docs #65

Open
poltak opened this issue Jun 24, 2017 · 2 comments

Comments

@poltak
Copy link

poltak commented Jun 24, 2017

Hello. Currently trying to get this working restoring from a dump in our web extension. Everything's currently happening in the browser, using memorystream to handle the node-like streams.

Dumping is working fine: in some test code, I can collect the dump string all in memory, build an in-memory File, then creating an object URL to download it as a file.

Can read it back in to memory through a input[type='file'] and use FileReader to write its contents to another stream (FileReader.readAsText()) and pass that stream to .load(). However that's throwing the following TypeError once I signal end on the stream:

Uncaught (in promise) TypeError: Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'.
    at readAsArrayBuffer (index.js:4198)
    at appendBlob (index.js:4222)
    at loadNextChunk (index.js:4265)
    at binaryMd5 (index.js:4268)
    at preprocessBlob (index.js:4306)
    at preprocessAttachment (index.js:4333)
    at index.js:4365
    at Array.forEach (<anonymous>)
    at preprocessAttachments (index.js:4346)
    at idbBulkDocs (index.js:4839)

Creating a test Pouch instance and just doing a direct await Promise.all([db.dump(stream), testDB.load(stream)]) is throwing the same error.

Checking the DB, it loads in 400 docs, however the dump contains more than that.

Furthermore, using the pouchdb-load plugin (putting it on a different namespace to .load(), of course) and using FileReader.readAsText() to just pass the text content of the dump file straight into that package's .load() gives the same error. I understand that is a different package to this repo, but the fact that its throwing the same error may indicate something?

Trying with dumps from different DB contents gives the same thing. The dumps look to be in the correct newline delimited JSON as documented here (not modifying them at all).

Probably I'm missing something obvious, but have you ever seen this or any ideas what's causing this? Is there something special about the number of 400 docs for restoring from dumps? Should I split the dump files into roughly 400 docs dumps then write them to the .load() stream in batches of 400?

Thanks for taking the time to read, and let me know if you need any further info 👍

@poltak
Copy link
Author

poltak commented Jun 27, 2017

Seems to be the _attachments on docs causing this issue, so probably related to the other attachment-related issues. Manually removing the doc _attachments and trying the same dump + restore code works fine on a restore.

Not sure if of any use, but the attachments on my docs include types image/x-icon, image/png, and text/html, all stored as Blobs.

@HarelM
Copy link

HarelM commented Jul 17, 2019

I get the same error only that I'm dumping the pouchdb from nodejs and loading the string in the browser.
Below is the file generated by nodejs' pouch and can't be imported using the following code:

tiles.txt

        let db = new PouchDB("Tiles", { adapter: "worker", auto_compaction: true })
        let reader = new FileReader();
        reader.onload = async (e: any) => {
            try {
                await db.load(e.target.result);
                console.log("Success!");
            } catch (ex) {
                console.log(ex);
            }
        };
        reader.readAsText(file);

I really need those attachments...
@poltak did you manage to solve this?

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

2 participants