Skip to content

Commit

Permalink
use MemoryStream instead of concat
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Aug 31, 2015
1 parent 4a1f4c6 commit 9158d1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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');
Expand All @@ -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
<script src="lib/pouchdb/dist/pouchdb.js"></script>
<script src="lib/pouchdb-replication-stream/dist/pouchdb.replication-stream.js"></script>
<script src="lib/concat-stream/concat-stream.js"></script>
<script src="lib/memorystream/memorystream.js"></script>
```

```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 () {
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 9158d1b

Please sign in to comment.