pouchdb-community / pouchdb-replication-stream

Replicate PouchDB/CouchDB databases with Node.js-style streams
Apache License 2.0
189 stars 58 forks source link

Invalid chunk error when trying to load a dumped Db #48

Closed limoragni closed 8 years ago

limoragni commented 8 years ago

I'm using PouchDb on electron with IndexedDb as a backend. So is the browser version of pouchdb. I'm dumping the database by using

var ws = fs.createWriteStream(path)
_db.dump(ws)

When I try to load the dumped db with

var rs = fs.createReadStream(path[0])
_db.load(rs)

I get the error Invalid non-string/buffer chunk The node version is 4.1.1

Any ideas on what could be the problem?

------- EDIT -------

From what I see it could be a problem of being using the browser version in a node environment or something like that. Given that the part that's failing is this one here.

    // this only applies in the browser
    /* istanbul ignore next */
    if (!(chunk instanceof Buffer) && Buffer.isBuffer(chunk)) {
      chunk = new Buffer(chunk);
    }
    this.push(chunk);

chunk instanceof Buffer is true so is not doing chunk = new Buffer(chunk); Later it tries to validate on the function validChunk using !Buffer.isBuffer(chunk) which is not passing because the _isBuffer property is undefined

limoragni commented 8 years ago

It was a problem of using it on the browser but with node (on Electron). If I install the package using npm it works. But I have to also install pouchdb using npm. So I ended up having two installations since I'm using pouchdb with indexedDb, because if I want to use it with leveldown I would have to build leveldown for each platform complicating my CI setting a lot. Is there a way of using the npm version with indexedb? Or I would like to have some pointers on how to patch pouchdb-replication-stream so it can contemplate this setting.

nolanlawson commented 8 years ago

Should be fixed by https://github.com/nolanlawson/pouchdb-replication-stream/pull/47. Thanks for reporting!