# @pyramation/content-type-stream

> detect content-types via streams

Latest version **0.1.0** (published 2020-10-01) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @pyramation/content-type-stream
pnpm add @pyramation/content-type-stream
yarn add @pyramation/content-type-stream
bun add @pyramation/content-type-stream
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-10-01 |
| First published | 2020-08-08 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Dan Lynch |
| Maintainers | pyramation |

## Links

- npm: https://www.npmjs.com/package/@pyramation/content-type-stream
- Repository: https://github.com/pyramation/uploads
- Homepage: https://github.com/pyramation/uploads/tree/master/packages/content-type-stream#readme
- Issues: https://github.com/pyramation/uploads/issues
- npm.io page: https://npm.io/package/@pyramation/content-type-stream

## Dependencies (6)

- [mime](https://npm.io/package/mime.md) 2.4.6
- [mmmagic](https://npm.io/package/mmmagic.md) 0.5.3
- [etag-hash](https://npm.io/package/etag-hash.md) 1.0.1
- [uuid-hash](https://npm.io/package/uuid-hash.md) 1.0.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.2
- [buffer-peek-stream](https://npm.io/package/buffer-peek-stream.md) 1.1.0

## Recent versions

- 0.1.0 (latest) — 2020-10-01
- 0.0.5 — 2020-09-30
- 0.0.4 — 2020-08-08
- 0.0.3 — 2020-08-08
- 0.0.2 — 2020-08-08

## README

# content-type-stream

```sh
npm install @pyramation/content-type-stream
```

In my life I've always found that `content-type`s or mimetypes to be totally hacky and different across operating systems and browsers. Also, knowing when to use the magic bytes compared to how we actually use files based on their extensions is never consistent... so this is aimed to make all that simple :)

## content-type info

get proper content-type information via streams without ever reading to disk

```js
const readStream = createReadStream(filename);
const { stream, magic, contentType } = await streamContentType({
   readStream,
   filename
});
```

## using steams

the `stream` it returns can then be used, for example

```js
  const { stream, contentType } = await streamContentType({
    readStream,
    filename
  });
  return await asyncUpload({
    key,
    contentType,
    readStream: stream,
    bucket
  });
```

## contents hash stream

if you want more info with your upload, with `ContentStream` you can get nice hashes

* `uuid`: RFC-compliant UUID v5.
* `etag`: Etag/S3 MD5 sum
* `sha`: A sha sum

```js
    const contentStream = new ContentStream();
// ...
    readStream.pipe(contentStream);
    contentStream.pipe(uploadStream);
```

```js
   { 
        uuid: '78160718-8dfa-5cb4-bb50-e479c8c58383',
        sha: 'e6c7c64d292a414941d239c57117b36f24c9f829',
        etag: '64dcb5b3b291074d02c80f600fda3f6e'
    }
```

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