# attachmate

> CouchDB Attachment Helpers

Latest version **1.0.0** (published 2017-06-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install attachmate
pnpm add attachmate
yarn add attachmate
bun add attachmate
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-06-15 |
| First published | 2011-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Damon Oehlman |
| Maintainers | damonoehlman |
| Keywords | couchdb, attachment, download, upload |

## Links

- npm: https://www.npmjs.com/package/attachmate
- Repository: https://github.com/DamonOehlman/attachmate
- Homepage: https://github.com/DamonOehlman/attachmate#readme
- Issues: http://github.com/DamonOehlman/attachmate/issues
- npm.io page: https://npm.io/package/attachmate

## Dependencies (4)

- [mime](https://npm.io/package/mime.md) ^1
- [debug](https://npm.io/package/debug.md) *
- [fstream](https://npm.io/package/fstream.md) ^1.0.11
- [request](https://npm.io/package/request.md) ^2

## Recent versions

- 1.0.0 (latest) — 2017-06-15
- 0.1.7 — 2014-05-18
- 0.1.6 — 2013-11-05
- 0.1.5 — 2012-09-08
- 0.1.4 — 2012-08-27
- 0.1.3 — 2012-06-27
- 0.1.2 — 2012-03-02
- 0.1.1 — 2011-12-30
- 0.1.0 — 2011-12-19

## README

# attachmate

Streamable CouchDB attachments

An experiment in using @isaacs useful
[fstream](https://github.com/isaacs/fstream) project to stream files in
and out of [CouchDB](http://couchdb.apache.org/) as attachments to
documents.


[![NPM](https://nodei.co/npm/attachmate.png)](https://nodei.co/npm/attachmate/)

[![stable](https://img.shields.io/badge/stability-stable-green.svg)](https://github.com/dominictarr/stability#stable) [![Build Status](https://api.travis-ci.org/DamonOehlman/attachmate.svg?branch=master)](https://travis-ci.org/DamonOehlman/attachmate) [![bitHound Score](https://www.bithound.io/github/DamonOehlman/attachmate/badges/score.svg)](https://www.bithound.io/github/DamonOehlman/attachmate) 

## Downloading From Couch to FileSystem

### Example: Download Attachments to the Filesystem

```js
var attachmate = require('attachmate');
var fstream = require('fstream');
var path = require('path');
var outputPath = path.resolve(__dirname, 'output');
var mkdirp = require('mkdirp');

mkdirp(outputPath, function(err) {
  if (err) return;

  var r = fstream.Reader({
    type: attachmate.Reader,
    path: 'http://localhost:5984/testdb/test'
  });

  var w = fstream.Writer({
    path: outputPath,
    type: 'Directory'
  });

  // pipe the attachments to the directory
  r.pipe(w);
});


```

### Example: Download Attachments (using download helper)

```js
var attachmate = require('attachmate');
var path = require('path');
var outputPath = path.resolve(__dirname, 'output');
var mkdirp = require('mkdirp');

mkdirp(outputPath, function(err) {
  if (err) return;

  attachmate.download(
    'http://localhost:5984/testdb/test',
    outputPath,
    function(err) {
      console.log('done, error = ', err);
    }
  );
});


```

## Uploading from Filesystem to Couch

### Options

The fstream classes take a set of options at initialization.  In keeping
with the fstream standard, we use the `path` option to denote the target
document.  The following additional options are also supported:

- `preserveExisting` - whether or not existing attachments on the
  document should be preserved. (default = true)

- `includeHidden` - whether or not hidden files should be included when
   uploading attachments to couch. (default = false)

### Example: Upload Attachments from the Filesystem

```js
var attachmate = require('attachmate');
var fstream = require('fstream');
var path = require('path');

var r = fstream.Reader({
  path: path.resolve(__dirname, 'input'),
  type: 'Directory'
});

var w = new attachmate.Writer({
  path: 'http://localhost:5984/testdb/test',
  includeHidden: false,
  preserveExisting: true
});

// pipe the attachments to the directory
r.pipe(w);
```

### Example: Upload Attachments (using upload helper)

```js
var attachmate = require('attachmate');
var path = require('path');

attachmate.upload(
  'http://localhost:5984/testdb/test',
  path.resolve(__dirname, 'input'),
  function(err) {
    console.log('done, error = ', err);
  }
);
```

## Reference

## AttachmentReader

### _getEntries()

### _read()

### pause()

### resume()

## HttpRequestEntry(targetDoc, path)

### _getStream()

### _read()

### pause()

### resume()

## AttachmentWriter(props)

### add()

### end()

### _addAttachment(name, chunks, size)

### _process()

## License(s)

### MIT

Copyright (c) 2017 Damon Oehlman <damon.oehlman@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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