# s3-storage

> Small module wrapper for the AWS sdk that allows you to easily use s3 or the local file system

Latest version **4.1.0** (published 2019-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install s3-storage
pnpm add s3-storage
yarn add s3-storage
bun add s3-storage
```

## 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 | 4.1.0 |
| Published | 2019-11-12 |
| First published | 2018-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 28.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Mathias Buus |
| Maintainers | emilbayes, mafintosh |

## Links

- npm: https://www.npmjs.com/package/s3-storage
- Repository: https://github.com/mafintosh/s3-storage
- Issues: https://github.com/mafintosh/s3-storage/issues
- npm.io page: https://npm.io/package/s3-storage

## Dependencies (9)

- [mime](https://npm.io/package/mime.md) ^2.2.0
- [from2](https://npm.io/package/from2.md) ^2.3.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [thunky](https://npm.io/package/thunky.md) ^1.0.2
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.184.0
- [duplexify](https://npm.io/package/duplexify.md) ^4.1.1
- [stream-each](https://npm.io/package/stream-each.md) ^1.2.2
- [readable-stream](https://npm.io/package/readable-stream.md) ^3.4.0
- [bulk-write-stream](https://npm.io/package/bulk-write-stream.md) ^2.0.1

## Recent versions

- 4.1.0 (latest) — 2019-11-12
- 4.0.0 — 2019-11-06
- 3.1.0 — 2019-09-05
- 3.0.0 — 2019-09-03
- 2.1.0 — 2019-01-09
- 2.0.1 — 2018-06-12
- 2.0.0 — 2018-02-08
- 1.2.1 — 2018-02-07
- 1.2.0 — 2018-02-07
- 1.1.0 — 2018-02-07
- 1.0.5 — 2018-02-05
- 1.0.4 — 2018-01-25
- 1.0.3 — 2018-01-18
- 1.0.2 — 2018-01-18
- 1.0.1 — 2018-01-18
- … 1 more at https://npm.io/package/s3-storage/versions

## README

# s3-storage

Small module wrapper for the AWS sdk that allows you to easily use s3.

Supports the local file system as well with the same set of operations so you can easily develop without having internet access

```
npm install s3-storage
```

[![build status](https://travis-ci.org/mafintosh/s3-storage.svg?branch=master)](https://travis-ci.org/mafintosh/s3-storage)

## Usage

``` js
var s3 = require('s3-storage')('my-bucket', {
  secretAccessKey: '...',
  accessKeyId: '...'
})

s3.put('hello', 'world', function () {
  s3.get('hello', console.log)
})
```

Or if you want use the file system locally instead

``` js
var s3 = require('s3-storage')('my-bucket', {
  type: 'fs' // will store the data in ./my-bucket
})

// s3 has the same api
```

## API

#### `var s3 = s3storage(bucket, [options])`

Make a new storage instance. Options include:

``` js
{
  type: 's3' | 'fs' // defaults to s3
  secretAccessKey: '...'
  accessKeyId: '...', // both forwarded to the AWS sdk
  region: 'us-west-2', // the default region
  // Prefix all operations. eg `test` to prefix all under `test/`
  // note that '' results in the empty prefix, which means all your objects
  // will go in the folder `/`
  prefix: null
}
```

#### `s3.put(key, value, [metadata], [callback])`

Write a new value.

#### `s3.get(key, callback)`

Read a value out

#### `s3.del(key, [callback])`

Delete a value

#### `s3.delBatch(objects, [callback])`

Delete multiple values. Objects should look like this:

```js
{
  key: `value/key`, // required
  version: `version` // optional
}
```

#### `s3.createReadStream(key, options)`

Create a readable stream to a key.

#### `s3.createWriteStream(key, options)`

Create a writeable stream to a key. Options include

``` js
{
  length: sizeOfStream, // required
}
```

#### `s3.rename(src, dest, [callback])`

Rename a folder/file

#### `s3.exists(key, callback)`

Check if a key exists.

#### `s3.stat(key, callback)`

Return stat info about a key. The returned object looks like this:

``` js
{
  size: sizeOfValue,
  modified: lastModifiedDate
}
```

#### `s3.versions(key, callback)`

Get a list of versions of a specific key. You can pass the version to `stat`, `exists`, `get`, `createReadStream` and `del`
to interact with a specific one.

#### `var stream = s3.list([options])`

Create a list stream. Each data emitted looks like this

``` js
{
  key: 'value/key', // the value key
  size: 24, // how many bytes
  modified: Date() // when was it modified last?
}
```

Options include:

``` js
{
  prefix: 'foo', // only list keys under foo
  marker: 'foo/bar/baz', // only list keys after foo/bar/baz
  limit: 14 // only return this many
}
```

## Acknowledgements

This project was kindly sponsored by nearForm.

## License

MIT

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