Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #26 from Borewit/tokenizer-range
Browse files Browse the repository at this point in the history
Switch from @tokenizer/range to streaming-http-token-reader
  • Loading branch information
Borewit authored Dec 11, 2019
2 parents 0efdf0f + 341c203 commit ab1ce7f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ update_configs:
- match:
dependency_name: "@types/node"
update_type: "semver:minor"
- match:
dependency_name: "@types/chai"
update_type: "semver:minor"
- match:
dependency_name: "ts-node"
- match:
Expand Down
13 changes: 6 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as S3 from 'aws-sdk/clients/s3';
import { parseFromTokenizer, parseStream } from 'music-metadata/lib/core';
import { StreamingHttpTokenReader, IHttpClient, IHttpResponse } from 'streaming-http-token-reader';
import { parseContentRange } from 'streaming-http-token-reader/lib/http-client';
import { RangeRequestTokenizer, IRangeRequestClient, IRangeRequestResponse, parseContentRange } from '@tokenizer/range';
import { AWSError, Request } from 'aws-sdk';
import { IOptions, IAudioMetadata } from 'music-metadata/lib/type';

Expand All @@ -17,12 +16,12 @@ interface IS3Options extends IOptions {
/**
* Use S3-client to execute actual HTTP-requests.
*/
class S3Request implements IHttpClient {
class S3Request implements IRangeRequestClient {

constructor(private s3client: MMS3Client, private objRequest: S3.Types.GetObjectRequest) {
}

public async getResponse(method, range: number[]): Promise<IHttpResponse> {
public async getResponse(method, range: number[]): Promise<IRangeRequestResponse> {

return this.s3client.getRangedRequest(this.objRequest, range).promise().then(data => {
return {
Expand Down Expand Up @@ -69,11 +68,11 @@ export class MMS3Client {
return parseStream(stream, info.ContentType, options);
} else {
const s3Request = new S3Request(this, objRequest);
const streamingHttpTokenReader = new StreamingHttpTokenReader(s3Request, {
const rangeRequestTokenizer = new RangeRequestTokenizer(s3Request, {
avoidHeadRequests: true
});
await streamingHttpTokenReader.init();
return parseFromTokenizer(streamingHttpTokenReader, streamingHttpTokenReader.contentType, options);
await rangeRequestTokenizer.init();
return parseFromTokenizer(rangeRequestTokenizer, rangeRequestTokenizer.contentType, options);
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"music-metadata": "^5.0.0",
"streaming-http-token-reader": "^0.3.1"
"@tokenizer/range": "^0.1.0"
},
"devDependencies": {
"aws-sdk": "^2.528.0",
Expand Down
23 changes: 9 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
"@nodelib/fs.scandir" "2.1.3"
fastq "^1.6.0"

"@tokenizer/range@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@tokenizer/range/-/range-0.1.0.tgz#3be97516213694a4995c08dee869c32ff3555f02"
integrity sha512-wIojK1GDoD4lhuaDganB5JiOtNOWzRJnVgwKSdUQmx+UYiQpLWR02JpOoJcy9P7/rT78Pb86BkfmyTLLXc/XOg==
dependencies:
debug "^4.1.1"
mocha "^6.2.2"
strtok3 "^3.0.4"

"@types/events@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
Expand Down Expand Up @@ -874,11 +883,6 @@ [email protected]:
object.getownpropertydescriptors "^2.0.3"
semver "^5.7.0"

node-fetch@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==

normalize-package-data@^2.3.2, normalize-package-data@^2.3.4:
version "2.5.0"
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8"
Expand Down Expand Up @@ -1154,15 +1158,6 @@ sprintf-js@~1.0.2:
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=

streaming-http-token-reader@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/streaming-http-token-reader/-/streaming-http-token-reader-0.3.1.tgz#fab384060fb214d7ffa70f00a4c669413695370f"
integrity sha512-8HLGXNvGvGWgwACaHXbj5DSPCItXn9rbXkzz6q3uDYTjjx1lqhCGKttHUC8iqDFPY7U2FcpXh3A4WKr6EiXntg==
dependencies:
debug "^4.1.1"
node-fetch "^2.6.0"
strtok3 "^3.0.4"

"string-width@^1.0.2 || 2":
version "2.1.1"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
Expand Down

0 comments on commit ab1ce7f

Please sign in to comment.