jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.06k stars 215 forks source link

How to copy from ZipFS to IndexedDB #259

Closed ajainvivek closed 5 years ago

ajainvivek commented 5 years ago

How to copy file from ZipFS to IndexedDB, I tried accessing with OverlayFS but returns empty list item

My assumption from below piece of code is zipData is written to index db but while accessing the indexed db, it returns empty list items

       BrowserFS.configure({
                fs: "OverlayFS",
                options: {
                    readable: {
                        fs: "ZipFS",
                        options: {
                            zipData: Buffer.from(zipData)
                        }
                    },
                    writable: {
                        fs: "IndexedDB",
                        options: {
                            storeName: "site"
                        }
                    }
                }
            }, function(e) {
                if (e) {
                    // An error occurred.
                    throw e;
                }
                BrowserFS.configure({
                    fs: "IndexedDB",
                    options: {
                        storeName: "site"
                    }
                }, () => {
                    // // Otherwise, BrowserFS is ready to use!
                    fs.stat("/code", function(err, stat) {
                        fs.readdir("/code", function(err, list) {
                            console.log(err, list); //returns empty list
                        })
                    });
                });
        });
jvilk commented 5 years ago

You should only use OverlayFS if you need to make some read-only file system writable. It doesn't copy items into the overlay.

If you just want to copy things from file system A to file system B, consider using MountableFileSystem to mount them into different folders. Then, you can write a routine that recursively copies files from folder1 to folder2.