diff --git a/README.md b/README.md index b2ab93e..93555b3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ PouchDB Replication Stream [![Build Status](https://travis-ci.org/nolanlawson/pouchdb-replication-stream.svg)](https://travis-ci.org/nolanlawson/pouchdb-replication-stream) -`ReadableStream`s and `WritableStream`s for PouchDB/CouchDB replication. +`ReadableStream`s and `WritableStream`s for PouchDB/CouchDB replication. Basically, you can replicate two databases by just attaching the streams together. @@ -200,22 +200,25 @@ Promise.all([ Dumping to a string --- -You can use [`concat-stream`](https://github.com/maxogden/concat-stream) to read in the entire +You can use [`MemoryStream`](https://github.com/JSBizon/node-memorystream) to read in the entire stream and dump it to a string. + + Example: ```js var PouchDB = require('pouchdb'); var replicationStream = require('pouchdb-replication-stream'); -var concat = require('concat-stream'); +var MemoryStream = require('memorystream'); PouchDB.plugin(replicationStream.plugin); PouchDB.adapter('writableStream', replicationStream.adapters.writableStream); var dumpedString = ''; -var stream = concat({encoding: 'string'}, function (line) { - dumpedString += line; +var stream = new MemoryStream(); +stream.on('data', function(chunk) { + dumpedString += chunk.toString(); }); var db = new PouchDB('my_db'); @@ -227,24 +230,26 @@ db.dump(stream).then(function () { }); ``` -This will also work in the browser via [Browserify](http://browserify.org/). If you aren't using Browserify, then you can download `concat-stream` from [https://wzrd.in/standalone/concat-stream@latest](https://wzrd.in/standalone/concat-stream@latest) and it will be available as `window.concatStream`. +This will also work in the browser via [Browserify](http://browserify.org/). + +If you aren't using Browserify, then you can download `MemoryStream` from [https://wzrd.in/standalone/memorystream@latest](https://wzrd.in/standalone/memorystream@latest) and it will be available as `window.memorystream`. Example: ```html - + ``` ```js var db = new PouchDB('my_db'); -var concat = window.concatStream; +var MemoryStream = window.MemoryStream; var dumpedString = ''; -var stream = concat({encoding: 'string'}, function (line) { - dumpedString += line; +stream.on('data', function(chunk) { + dumpedString += chunk.toString(); }); db.dump(stream).then(function () { @@ -282,7 +287,7 @@ Testing This will run the tests in Node using LevelDB: npm test - + You can also check for 100% code coverage using: npm run coverage diff --git a/package.json b/package.json index 547a296..2b66bc2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "browserify": "^9.0.8", "chai": "~1.8.1", "chai-as-promised": "~4.1.0", - "concat-stream": "^1.4.8", "derequire": "^2.0.0", "es3ify": "^0.1.3", "http-server": "~0.5.5", diff --git a/test/test.js b/test/test.js index c5e3d37..968720f 100644 --- a/test/test.js +++ b/test/test.js @@ -211,11 +211,12 @@ function tests(dbName, dbType) { it('should dump to a string', function () { - var concat = require('concat-stream'); + var MemoryStream = require('memorystream'); var dumpedString = ''; - var readStream = concat({encoding: 'string'}, function (line) { - dumpedString += line; + var readStream = new MemoryStream(); + readStream.on('data', function (chunk) { + dumpedString += chunk.toString(); }); return db.put({_id: '1'}).then(function () {