# pouch-remote-stream

> PouchDB remote stream

Latest version **0.3.0** (published 2016-05-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install pouch-remote-stream
pnpm add pouch-remote-stream
yarn add pouch-remote-stream
bun add pouch-remote-stream
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2016-05-31 |
| First published | 2015-10-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | pgte |
| Maintainers | pgte |

## Links

- npm: https://www.npmjs.com/package/pouch-remote-stream
- Repository: https://github.com/pgte/pouch-remote-stream
- Homepage: https://github.com/pgte/pouch-remote-stream#readme
- Issues: https://github.com/pgte/pouch-remote-stream/issues
- npm.io page: https://npm.io/package/pouch-remote-stream

## Dependencies (6)

- [lie](https://npm.io/package/lie.md) 3.0.0
- [once](https://npm.io/package/once.md) ^1.3.2
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [xtend](https://npm.io/package/xtend.md) ^4.0.0
- [argsarray](https://npm.io/package/argsarray.md) 0.0.1
- [duplexify](https://npm.io/package/duplexify.md) ^3.4.2

## Recent versions

- 0.3.0 (latest) — 2016-05-31
- 0.2.0 — 2015-11-12
- 0.1.3 — 2015-10-26
- 0.1.2 — 2015-10-26
- 0.1.0 — 2015-10-24

## README

# pouch-remote-stream

[![By](https://img.shields.io/badge/made%20by-yld!-32bbee.svg?style=flat)](http://yld.io/contact?source=github-nock)
[![Build Status](https://secure.travis-ci.org/pgte/pouch-remote-stream.svg)](http://travis-ci.org/pgte/pouch-remote-stream)

Consume a remote [PouchDB](http://pouchdb.com/) stream.

Goes well with [`pouch-stream-server`](https://github.com/pgte/pouch-stream-server) on the server side.


## PouchDB versions

Tested against PouchDB version 5.

## Install

```
$ npm install pouch-remote-stream --save
```


## Getting started

### 1. Require it

```js
var Remote = require('pouch-remote-stream');
```

### 2. Add the PouchDB adapter

```
PouchDB.adapter('remote', Remote.adapter);
```

### 3. Create the remote

```js
var remote = Remote();
```

### 4. Create the remote PouchDB database

```js
var remoteDB = new PouchDB('mydb', {
  adapter: 'remote',
  remote: remote 
});
```

### 5. Pipe it to and from a duplex stream

```js
var stream = somehowCreateSomeDuplexStream();

stream.pipe(remote.stream()).pipe(stream);
```

### 6. Use the PouchDB remote DB

, for example to sync a local DB:

```js
var localDB = new PouchDB('someLocalDB');
localDB.sync(remoteDB);
```


## Any stream, really

You can pipe it to and from any duplex object stream.


## Encode and decode streams

If you need to work with a raw duplex stream (like a TCP or a web socket), you will need to encode and decode the stream. For example, you can use a new-line separated JSON duplex stream like this:

```js
var JSONDuplexStream = require('json-duplex-stream');

var JSONStream = JSONDuplexStream();

var rawDuplexStream = createRawStreamSomehow();

// raw => JSON.in => remote.stream => JSON.out => raw

rawDuplexStream.
  pipe(JSONStream.in).
  pipe(remote.stream).
  pipe(JSONStream.out).
  pipe(rawDuplexStream);
```

## You can use with reconnect:

Here's an example of using a TCP stream and reconnecting if the connection goes down:

```js
var Remote = require('pouch-remote-stream');
PouchDB.adapter('remote', Remote.adapter);
var Reconnect = require('reconnect-core');

var reconnect = Reconnect(function(options) {
  return net.connect(options.port, options.host);
});

var options = {
  port: 80,
  host: '127.0.0.1'
};

var re = reconnect(options, function(stream) {
  var remote = Remote();

  var remoteDB = new PouchDB('mydb', {
    adapter: 'remote',
    remote: remote 
  });

  stream.pipe(remote.stream).pipe(stream);

  // use remoteDB

});
```

# License

ISC

---
_Source: https://npm.io/package/pouch-remote-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
