Skip to content

Commit

Permalink
Combine IS3Options options and base tokenizer options
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Aug 15, 2024
1 parent f09e6fa commit 4e977da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ yarn add install @tokenizer/s3 @aws-sdk/client-s3

To configure AWS client authentication see [Configuration and credential file settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html).

## API documentation


## Examples

### Determine S3 file type
Expand Down Expand Up @@ -65,7 +68,7 @@ const mm = require("music-metadata/lib/core");
/**
* Retrieve metadata from Amazon S3 object
* @param objRequest S3 object request
* @param options music-metadata options
* @param options `tokenizer-s3` options
* @return Metadata
*/
async function parseS3Object(s3, objRequest, options) {
Expand Down
10 changes: 5 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type S3Client, type GetObjectRequest, GetObjectCommand } from '@aws-sdk/client-s3';
import { parseContentRange, tokenizer } from '@tokenizer/range';
import { fromStream, type ITokenizer } from 'strtok3';
import { fromStream, type ITokenizer, type ITokenizerOptions } from 'strtok3';
import { S3Request } from './s3-request.js';
import type { Readable } from 'node:stream';

export interface IS3Options {
export interface IS3Options extends ITokenizerOptions {
/**
* Flag to disable chunked transfer, use conventional HTTPS stream instead
*/
Expand All @@ -15,7 +15,7 @@ export interface IS3Options {
* Initialize tokenizer from S3 object
* @param s3 S3 client
* @param objRequest S3 object request
* @param options music-metadata options
* @param options S3 tokenizer options
* @return Tokenizer
*/
export async function makeTokenizer(s3: S3Client, objRequest: GetObjectRequest, options?: IS3Options): Promise<ITokenizer> {
Expand All @@ -24,12 +24,12 @@ export async function makeTokenizer(s3: S3Client, objRequest: GetObjectRequest,
const info = await s3request.getRangedRequest([0, 0]);
const contentRange = parseContentRange(info.ContentRange as string);
const output = await s3.send(new GetObjectCommand(objRequest));
return fromStream(output.Body as Readable, {
return fromStream(output.Body as Readable, {...options, ...{
fileInfo: {
mimeType: info.ContentType,
size: contentRange.instanceLength
}
});
}});
}
return tokenizer(s3request, {
avoidHeadRequests: true
Expand Down

0 comments on commit 4e977da

Please sign in to comment.