# @e3o/gcp-storage

> Provides a storage handling solution.

Latest version **1.2.0** (published 2025-09-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install @e3o/gcp-storage
pnpm add @e3o/gcp-storage
yarn add @e3o/gcp-storage
bun add @e3o/gcp-storage
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2025-09-03 |
| First published | 2023-11-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 19.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | e3o |
| Maintainers | ajustor |

## Links

- npm: https://www.npmjs.com/package/@e3o/gcp-storage
- npm.io page: https://npm.io/package/@e3o/gcp-storage

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^9.0.1
- [@google-cloud/storage](https://npm.io/package/@google-cloud/storage.md) ^7.13.0

## Recent versions

- 1.2.0 (latest) — 2025-09-03
- 1.1.2 — 2025-08-05
- 1.1.1 — 2025-08-05
- 1.1.0 — 2025-07-30
- 1.0.3 — 2025-01-13
- 1.0.2 — 2024-07-24
- 1.0.1 — 2023-11-30
- 1.0.0 — 2023-11-30

## README

# storage

This modules provides methods manage object storage in Google Cloud Storage.

## How to use

### Import

```typescript
import { FileStorage } from 'storage'
```

### Init

First, we need an instance of FileStorage

```typescript
export const fileStorage = new FileStorage({
  bucket: 'BUCKET_NAME',
  keyFilename: 'STORAGE_KEY_FILENAME',
})
```

- `STORAGE_KEY_FILENAME` is the credential file URI

### Upload file

Upload a file to the remote storage.

```typescript
const fileName = await fileStorage.upload(
        {
            pathDestination: 'path',
            fileName: 'testFile',
            file: Buffer.from('Test content', 'utf-8'),
            contentType: "text/plain"
            metadata: { something: 'here' }
        }
)

// fileName -> path/testFile
```

```typescript
// OR
const fileName = await fileStorage.send(
        {
            pathDestination: 'path',
            fileName: 'testFile',
            file: fs.createReadStream('./test.png'),
            contentType: "img/png"
            metadata: { something: 'here' }
        }
)

// fileName -> path/testFile
```

- The `file` attribute MUST be a `Buffer` or a `ReadableStream`.
- The `contentType` attribute is not required default to "application/octet-stream"
- The `metadata` object is not required. Values are converted to `string`

### Download file

Download a file from the bucket

```typescript
const fileBuffer = await fileStorage.download(fileName)
```

- `fileName` is the string returned by the `upload()` method

### Misc

#### getMetadata

Get the global metadata of an object

```typescript
const metadata = await fileStorage.getMetadata(fileName)

/*
metadata ->
{ kind: 'storage#object',
  id: 'sandbox',
  selfLink:
   'https://www.googleapis.com/storage/v1/b/BUCKET_NAME/o/path%2FtestFile',
  name: 'path/testFile',
  bucket: 'BUCKET_NAME',
  generation: '123456789',
  metageneration: '1',
  contentType: 'application/octet-stream',
  storageClass: 'STANDARD',
  size: '12',
  md5Hash: 'MD5_HASH',
  mediaLink:
   'https://storage.googleapis.com/download/storage/v1/b/BUCKET_NAME/o/path%2FtestFile?generation=123456789&alt=media',
  cacheControl: 'public, max-age=31536000',
  crc32c: 'r5b9xg==',
  etag: 'CJD+6K2xsuUCEAE=',
  timeCreated: '2019-10-23T12:30:40.811Z',
  updated: '2019-10-23T12:30:40.811Z',
  timeStorageClassUpdated: '2019-10-23T12:30:40.811Z'
  metadata: { something: 'here', type: 'text' }
}

*/
```

- `fileName` is the string returned by the `upload()` method

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