Socket
Socket
Sign inDemoInstall

pouchdb-replication-stream

Package Overview
Dependencies
26
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.4 to 1.2.5

lib/index.js

24

package.json
{
"name": "pouchdb-replication-stream",
"version": "1.2.4",
"version": "1.2.5",
"description": "PouchDB/CouchDB replication as a stream",
"main": "index.js",
"main": "lib/index.js",
"repository": {

@@ -20,3 +20,3 @@ "type": "git",

"author": "",
"license": "Apache",
"license": "Apache-2.0",
"bugs": {

@@ -28,6 +28,6 @@ "url": "https://github.com/nolanlawson/pouchdb-replication-stream/issues"

"test-browser": "./bin/test-browser.js",
"jshint": "jshint -c .jshintrc *.js test/test.js",
"jshint": "jshint -c .jshintrc lib test/test.js",
"test": "npm run jshint && ./bin/run-test.sh",
"build": "mkdirp dist && npm run browserify && npm run min",
"browserify": "browserify index.js | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js",
"browserify": "browserify . | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js",
"min": "uglifyjs dist/pouchdb.replication-stream.js -mc > dist/pouchdb.replication-stream.min.js",

@@ -45,3 +45,2 @@ "dev": "browserify test/test.js > test/test-bundle.js && npm run dev-server",

"pouch-stream": "^0.4.0",
"pouchdb-extend": "^0.1.2",
"through2": "^0.6.1"

@@ -51,11 +50,10 @@ },

"bluebird": "^1.0.7",
"browserify": "^9.0.8",
"chai": "~1.8.1",
"chai-as-promised": "~4.1.0",
"concat-stream": "^1.4.8",
"browserify": "^11.2.0",
"chai": "^3.3.0",
"chai-as-promised": "^5.1.0",
"derequire": "^2.0.0",
"es3ify": "^0.1.3",
"http-server": "~0.5.5",
"http-server": "~0.8.5",
"istanbul": "^0.2.7",
"jshint": "~2.3.0",
"jshint": "^2.3.0",
"memorystream": "^0.3.0",

@@ -66,3 +64,3 @@ "mkdirp": "^0.5.0",

"phantomjs": "^1.9.7-5",
"pouchdb": "pouchdb/pouchdb",
"pouchdb": "^5.0.0",
"random-document-stream": "0.0.0",

@@ -69,0 +67,0 @@ "request": "^2.36.0",

@@ -6,3 +6,3 @@ PouchDB Replication Stream

`ReadableStream`s and `WritableStream`s for PouchDB/CouchDB replication.
`ReadableStream`s and `WritableStream`s for PouchDB/CouchDB replication.

@@ -21,4 +21,2 @@ Basically, you can replicate two databases by just attaching the streams together.

More to come.
* [pouchdb-dump-cli](https://github.com/nolanlawson/pouchdb-dump-cli)

@@ -28,2 +26,10 @@ * [pouchdb-load](https://github.com/nolanlawson/pouchdb-load)

Examples
------
You can use `pouchdb-replication-stream` itself to:
* [dump to a string](#dumping-to-a-string)
* [replicate with in-memory streams](https://github.com/nolanlawson/pouchdb-replication-stream#stream-directly-without-the-dump-file)
* do anything you can do with streams :)
Usage

@@ -94,5 +100,5 @@ -------

{"version":"0.1.0","db_type":"leveldb","start_time":"2014-09-07T21:31:01.527Z","db_info":{"doc_count":3,"update_seq":3,"db_name":"testdb"}}
{"docs":[{"_id":"doc1","_rev":"1-20624ff392c68c359adb98504a369769","foo":"bar"}]}
{"docs":[{"_id":"doc2","_rev":"1-8b6f55822a3e3932ac1e9ddb8b0357cb","bar":"baz"}]}
{"docs":[{"_id":"doc3","_rev":"1-2567345aa745c1d85602add2689dc398","baz":"quux"}]
{"docs":[{"_id":"doc1","_rev":"1-x","_revisions":{"start":1,"ids":["x"]},"foo":"bar"}]}
{"docs":[{"_id":"doc2","_rev":"1-y","_revisions":{"start":1,"ids":["y"]},"foo":"baz"}]}
{"docs":[{"_id":"doc3","_rev":"1-z","_revisions":{"start":1,"ids":["z"]},"foo":"quux"}]}
{"seq":3}

@@ -111,2 +117,4 @@ ```

For the time being, attachments are just included as base64-encoded strings, ala CouchDB's `_all_docs` with `attachments=true` and `Accept: application/json`.
Installation

@@ -130,3 +138,3 @@ --------

And then attach it to the `PouchDB` object using the following code:
In Node.js, you can attach it to the `PouchDB` object using the following code:

@@ -144,3 +152,3 @@ ```js

You can use a [`MemoryStream`](https://github.com/JSBizon/node-memorystream) to stream directly without dumping to a file. Here's an example:
On Node.js or with [`Browserify`](http://browserify.org/), ou can use a [`MemoryStream`](https://github.com/JSBizon/node-memorystream) to stream directly without dumping to a file. Here's an example:

@@ -165,11 +173,44 @@ ```js

console.log('Hooray the stream replication is complete!');
}).catch(function (err) {
console.log('oh no an error', err);
});
```
This will also work in the browser if you are using [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/memorystream/memorystream.js"></script>
```
```js
var localDB = new PouchDB('foo');
var remoteDB = new PouchDB('bar');
var source = new PouchDB('http://localhost:5984/source_db');
var dest = new PouchDB('local_destination');
Promise.all([
source.dump(stream),
dest.load(stream)
]).then(function () {
console.log('Hooray the stream replication is complete!');
}).catch(function (err) {
console.log('oh no an error', err);
});
```
Dumping to a string
---
You can use [`concat-stream`](https://github.com/maxogden/concat-stream) to read in the entire
stream and dump it to a string. This will also work in the browser if you browserify it.
You can use [`MemoryStream`](https://github.com/JSBizon/node-memorystream) to read in the entire
stream and dump it to a string.
Example:

@@ -180,3 +221,3 @@

var replicationStream = require('pouchdb-replication-stream');
var concat = require('concat-stream');
var MemoryStream = require('memorystream');

@@ -187,4 +228,5 @@ PouchDB.plugin(replicationStream.plugin);

var dumpedString = '';
var stream = concat({encoding: 'string'}, function (line) {
dumpedString += line;
var stream = new MemoryStream();
stream.on('data', function(chunk) {
dumpedString += chunk.toString();
});

@@ -196,6 +238,55 @@

console.log('Yay, I have a dumpedString: ' + dumpedString);
}).catch(function (err) {
console.log('oh no an error', err);
});
```
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/memorystream/memorystream.js"></script>
```
```js
var db = new PouchDB('my_db');
var MemoryStream = window.MemoryStream;
var dumpedString = '';
stream.on('data', function(chunk) {
dumpedString += chunk.toString();
});
db.dump(stream).then(function () {
console.log('Yay, I have a dumpedString: ' + dumpedString);
}).catch(function (err) {
console.log('oh no an error', err);
});
```
Known pitfalls
---
### Read error 400 ECONNRESET
Basically this means your CouchDB cannot handle all concurrent requests happening. Most probable cause is you have 200+ attachments on one of your documents.
One simple way to get around this error is to limit the globalAgent maxSockets, which manages the maximum number of concurret http requests.
```js
require('http').globalAgent.maxSockets = 25;
```
### Trying to speed up PouchDB replication?
If you are using this library in the browser, then it's not going to speed up replication. The whole point is to minify the number of HTTP requests by collapsing replication into a stream, and then sending one big chunk down the wire to the client. If you use it on the client side, then it will still make many small requests to the server, which is slow.
What you probably want is to use this library server-side, in a Node.js process. For a good example, see the Express wrapper: [express-pouchdb-replication-stream](https://github.com/conor-mac-aoidh/express-pouchdb-replication-stream).
Building

@@ -216,3 +307,3 @@ ----

npm test
You can also check for 100% code coverage using:

@@ -219,0 +310,0 @@

@@ -214,7 +214,8 @@ /*jshint expr:true */

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();
});

@@ -229,4 +230,26 @@

it('should dump and load using string', function () {
var dumpedString = '';
var readStream = new MemoryStream();
readStream.on('data', function (chunk) {
dumpedString += chunk.toString();
});
return db.put({_id: '1'}).then(function () {
return db.dump(readStream);
}).then(function () {
dumpedString.should.be.a('string', 'got a string');
var writeStream = new MemoryStream();
writeStream.end(dumpedString);
return remote.load(writeStream);
}).then(function () {
return remote.allDocs();
}).then(function (docs) {
docs.rows.should.have.length(1);
docs.rows[0].id.should.equal('1');
});
});
});
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc