@tokenizer/s3
Advanced tools
Comparing version 0.1.2 to 0.1.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.makeTokenizer = void 0; | ||
const range_1 = require("@tokenizer/range"); | ||
@@ -4,0 +5,0 @@ const strtok3 = require("strtok3/lib/core"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.S3Request = void 0; | ||
const range_1 = require("@tokenizer/range"); | ||
@@ -4,0 +5,0 @@ /** |
{ | ||
"name": "@tokenizer/s3", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Amazon S3 tokenizer", | ||
@@ -48,10 +48,10 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/mocha": "^5.2.7", | ||
"@typescript-eslint/eslint-plugin": "^2.14.0", | ||
"@typescript-eslint/parser": "^2.14.0", | ||
"@types/mocha": "^8.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.0.0", | ||
"@typescript-eslint/parser": "^3.0.0", | ||
"aws-sdk": "^2.528.0", | ||
"chai": "^4.2.0", | ||
"del-cli": "^3.0.0", | ||
"eslint": "^6.8.0", | ||
"mocha": "^7.0.0", | ||
"eslint": "^7.0.0", | ||
"mocha": "^8.0.1", | ||
"ts-node": "^8.5.4", | ||
@@ -58,0 +58,0 @@ "typescript": "^3.6.4" |
@@ -12,2 +12,4 @@ [![Build Status](https://travis-ci.org/Borewit/tokenizer-s3.svg?branch=master)](https://travis-ci.org/Borewit/tokenizer-s3) | ||
## Installation | ||
Install using [npm](https://www.npmjs.com/get-npm): | ||
```shell script | ||
@@ -17,8 +19,44 @@ npm install @tokenizer/s3 | ||
## Reading audio metadata from Amazon S3 | ||
or using [yarn](https://yarnpkg.com/): | ||
```shell script | ||
yarn add install @tokenizer/s3 | ||
``` | ||
## Examples | ||
### Determine S3 file type | ||
Determine file type (based on it's content) from a file stored Amazon S3 cloud: | ||
```js | ||
const FileType = require('file-type'); | ||
const S3 = require('aws-sdk/clients/s3'); | ||
const { makeTokenizer } = require('@tokenizer/s3'); | ||
(async () => { | ||
// Initialize S3 client | ||
const s3 = new S3(); | ||
// Initialize S3 tokenizer | ||
const s3Tokenizer = await makeTokenizer(s3, { | ||
Bucket: 'affectlab', | ||
Key: '1min_35sec.mp4' | ||
}); | ||
// Figure out what kind of file it is | ||
const fileType = await FileType.fromTokenizer(s3Tokenizer); | ||
console.log(fileType); | ||
})(); | ||
``` | ||
See also [example at file-type](https://github.com/sindresorhus/file-type#filetypefromtokenizertokenizer). | ||
### Reading audio metadata from Amazon S3 | ||
Retrieve music-metadata | ||
```js | ||
const s3tokenizer = require("@tokenizer/s3"); | ||
const S3 = require('aws-sdk/clients/s3'); | ||
const mm = require("music-metadata/lib/core"); | ||
/** | ||
@@ -31,4 +69,4 @@ * Retrieve metadata from Amazon S3 object | ||
async function parseS3Object(s3, objRequest, options) { | ||
const s3Tokenizer = await s3tokenizer.makeTokenizer(s3, objRequest, options); | ||
return mm.parseFromTokenizer(s3Tokenizer, options); | ||
const s3Tokenizer = await s3tokenizer.makeTokenizer(s3, objRequest, options); | ||
return mm.parseFromTokenizer(s3Tokenizer, options); | ||
} | ||
@@ -38,10 +76,13 @@ | ||
const s3 = new S3(); | ||
const metadata = await mmS3client.parseS3Object({ | ||
Bucket: 'music-metadata', | ||
Key: 'Various Artists - 2008 - netBloc Vol 13 (color in a world of monochrome) {BSCOMP0013} [MP3-V0]/01 - Nils Hoffmann - Sweet Man Like Me.mp3' | ||
} | ||
); | ||
const metadata = await parseS3Object(s3, { | ||
Bucket: 'standing0media', | ||
Key: '01 Where The Highway Takes Me.mp3' | ||
} | ||
); | ||
console.log(metadata); | ||
})(); | ||
``` | ||
An module implementation of this example can be found in [@music-metadata/s3](https://github.com/Borewit/music-metadata-s3). | ||
@@ -48,0 +89,0 @@ |
8177
103
89