Skip to content

Commit

Permalink
Update strtok3 to v8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Jul 16, 2024
1 parent 7d6da2b commit c21dd57
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function parseBlob(blob: Blob, options: IOptions = {}): Promise<IAu
if (blob instanceof File) {
fileInfo.path = (blob as File).name;
}
return parseWebStream(blob.stream() as any, fileInfo, options);
return parseWebStream(blob.stream(), fileInfo, options);
}

/**
Expand All @@ -40,7 +40,7 @@ export async function parseBlob(blob: Blob, options: IOptions = {}): Promise<IAu
* @returns Metadata
*/
export function parseWebStream(webStream: AnyWebStream<Uint8Array>, fileInfo?: strtok3.IFileInfo | string, options: IOptions = {}): Promise<IAudioMetadata> {
return parseFromTokenizer(strtok3.fromWebStream(webStream as any, typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo), options);
return parseFromTokenizer(strtok3.fromWebStream(webStream as any, {fileInfo: typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo}), options);
}

/**
Expand All @@ -56,7 +56,7 @@ export async function parseBuffer(uint8Array: Uint8Array, fileInfo?: strtok3.IFi
const bufferReader = new RandomUint8ArrayReader(uint8Array);
await scanAppendingHeaders(bufferReader, options);

const tokenizer = strtok3.fromBuffer(uint8Array, typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo);
const tokenizer = strtok3.fromBuffer(uint8Array, {fileInfo: typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo});
return parseFromTokenizer(tokenizer, options);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const debug = initDebug('music-metadata:parser');
* @returns Metadata
*/
export async function parseStream(stream: Stream.Readable, fileInfo?: strtok3.IFileInfo | string, options: IOptions = {}): Promise<IAudioMetadata> {
const tokenizer = await strtok3.fromStream(stream, typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo);
const tokenizer = await strtok3.fromStream(stream, {fileInfo: typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo});
return parseFromTokenizer(tokenizer, options);
}

Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
"name": "Borewit",
"url": "https://github.com/Borewit"
},
"funding": [{
"type": "github",
"url": "https://github.com/sponsors/Borewit"
}, {
"type": "buymeacoffee",
"url": "https://buymeacoffee.com/borewit"
}],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/Borewit"
},
{
"type": "buymeacoffee",
"url": "https://buymeacoffee.com/borewit"
}
],
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -97,7 +100,7 @@
"debug": "^4.3.4",
"file-type": "^19.1.1",
"media-typer": "^1.1.0",
"strtok3": "^7.1.0",
"strtok3": "^8.0.0",
"token-types": "^6.0.0",
"uint8array-extras": "^1.3.0"
},
Expand Down
3 changes: 2 additions & 1 deletion test/test-file-mpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ describe('Parse MPEG', () => {
const stream = new SourceStream(buffer);

const metadata = await mm.parseStream(stream, {mimeType: 'audio/mpeg'}, {duration: true});
assert.approximately(metadata.format.duration, 34.66, 5 / 1000);
// Changed expected result from 34.66 to 34.64, after updating strtok3
assert.approximately(metadata.format.duration, 34.64, 5 / 1000);
});

});
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,11 @@ peek-readable@^5.1.1:
resolved "https://registry.yarnpkg.com/peek-readable/-/peek-readable-5.1.1.tgz#7dbeafa1ce271a3eba3fba808883bdb03769b822"
integrity sha512-4hEOSH7KeEaZpMDF/xfm1W9fS5rT7Ett3BkXWHqAEzRLLwLaHkwOL+GvvpIEh9UrvX9BDhzfkvteslgraoH69w==

peek-readable@^5.1.3:
version "5.1.3"
resolved "https://registry.yarnpkg.com/peek-readable/-/peek-readable-5.1.3.tgz#08993b35dd87502ae5e6028498663abed2dcc009"
integrity sha512-kCsc9HwH5RgVA3H3VqkWFyGQwsxUxLdiSX1d5nqAm7hnMFjNFX1VhBLmJoUY0hZNc8gmDNgBkLjfhiWPsziXWA==

picocolors@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1"
Expand Down Expand Up @@ -4396,6 +4401,14 @@ strtok3@^7.1.0:
"@tokenizer/token" "^0.3.0"
peek-readable "^5.1.1"

strtok3@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/strtok3/-/strtok3-8.0.0.tgz#0b44ef1032f791e36091ea2365fa8590dc695b4c"
integrity sha512-YzsSP+kli3q1tTA04HsfY1GqIapi3vEMN38jJ+aLpFyoev0onI/RuZWBGkQgc7ORynb3LW4cSOP3XtsKV21X6Q==
dependencies:
"@tokenizer/token" "^0.3.0"
peek-readable "^5.1.3"

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
Expand Down

0 comments on commit c21dd57

Please sign in to comment.