# @janiscommerce/s3

> A package to handle the AWS S3 requests

Latest version **2.0.3** (published 2024-08-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install @janiscommerce/s3
pnpm add @janiscommerce/s3
yarn add @janiscommerce/s3
bun add @janiscommerce/s3
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2024-08-15 |
| First published | 2019-12-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Janis |
| Maintainers | janiscommerce |

## Links

- npm: https://www.npmjs.com/package/@janiscommerce/s3
- Repository: https://github.com/janis-commerce/s3
- Homepage: https://github.com/janis-commerce/s3.git#readme
- Issues: https://github.com/janis-commerce/s3/issues
- npm.io page: https://npm.io/package/@janiscommerce/s3

## Dependencies (4)

- [@aws-sdk/client-s3](https://npm.io/package/@aws-sdk/client-s3.md) ^3.632.0
- [@aws-sdk/lib-storage](https://npm.io/package/@aws-sdk/lib-storage.md) ^3.632.0
- [@aws-sdk/s3-presigned-post](https://npm.io/package/@aws-sdk/s3-presigned-post.md) ^3.632.0
- [@aws-sdk/s3-request-presigner](https://npm.io/package/@aws-sdk/s3-request-presigner.md) ^3.632.0

## Recent versions

- 2.0.3 (latest) — 2024-08-15
- 2.0.2 — 2023-09-26
- 2.0.1 — 2023-06-09
- 2.0.0 — 2023-03-03
- 1.5.1 — 2022-11-28
- 1.5.0 — 2022-09-05
- 1.4.1 — 2020-12-11
- 1.4.0 — 2020-11-12
- 1.3.0 — 2020-04-27
- 1.2.1 — 2019-12-16
- 1.2.0 — 2019-12-11
- 1.1.0 — 2019-12-06
- 1.0.0 — 2019-12-06

## README

# s3

![Build Status](https://github.com/janis-commerce/s3/workflows/Build%20Status/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/janis-commerce/s3/badge.svg?branch=master)](https://coveralls.io/github/janis-commerce/s3?branch=master)
[![npm version](https://badge.fury.io/js/%40janiscommerce%2Fs3.svg)](https://www.npmjs.com/package/@janiscommerce/s3)

A package to handle the S3 requests

## Installation
```sh
npm install @janiscommerce/s3
```
## Description
This is a wrapper for the AWS SDK for the management S3 request, that makes easier the use of it.

For more information read the [AWS S3 SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html).

> Since `v2.0.0` you need Node 18

The possible methods are:

* `getObject`
* `getObjectRaw`
* `putObject`
* `headObject`
* `copyObject`
* `deleteObject`
* `deleteObjects`
* `listObjects`
* `listBuckets`
* `createBucket`
* `deleteBucket`
* `getSignedUrl`
* `createPresignedPost`

### getObject

Since the package updates to use SDK v3 and Node-18 compatibility, when use `getObject`, it returns the `Body` as an `Readable` type. This change is not compatible with previous uses.

So `getObject` method convert the `Body` into a `Buffer` type object, to keep the compatibility with previous uses.

> If you wanted the original behavior, you can use `getObjectRaw`.

## Usage
```js
const S3 = require('@janiscommerce/s3');

try {
	const s3Response = await S3.putObject({
		Body: 'File content',
		Bucket: 'bucket-ame',
		Key: `path/to/file.txt`
	});
	console.log(s3Response);
} catch(err) {
	handleError(err);
}
```

## Streams

For manage stream the package provide

### GetObjectStream

The class to get, parse and process S3 streams.

#### Usage
```js
const { GetObjectStream } = require('@janiscommerce/s3');

class MyGetObjectStream extends GetObjectStream {

	// Parse the incoming data before process rows
	get parsers() {
		return [
			/*
			* Your parsers here as array, where:
			* [function, ...params]
			*/
		]
	}

	// Manage the buffer rows size
	get bufferSize() {
		return 10;
	}

	// Process the buffered rows and return and array to continue.
	async processBuffer(buffer) {
		// ... Your logic here ...
	}

}

const myGetObjectStream = new MyGetObjectStream();

const myProcessedStream = myGetObjectStream.call({
	Bucket: 'bucket-ame',
	Key: `path/to/file.txt`
});
```

### uploadStream

Method to manage streams upload

#### Usage
```js
const { uploadStream } = require('@janiscommerce/s3');

try {
	const response = await uploadStream(someStream, {
		Bucket: 'bucket-ame',
		Key: `path/to/file.txt`
	});
} catch(e) {
	console.log(e)
}
```

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