music-metadata 12.2.0 → 12.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { type ITokenizer } from 'strtok3';
2
+ import type { INativeMetadataCollector } from '../common/MetadataCollector.js';
3
+ import type { IOptions } from '../type.js';
4
+ /** Borrow the chunk payload; consume its remainder while leaving container padding to the caller. */
5
+ export declare function parseEmbeddedID3v2(metadata: INativeMetadataCollector, tokenizer: ITokenizer, options: IOptions, size: number): Promise<void>;
@@ -0,0 +1,29 @@
1
+ import { createTokenizerView, EndOfStreamError, TokenizerBoundaryError } from 'strtok3';
2
+ import { validateAllocation } from '../common/Allocation.js';
3
+ import { Id3v2ContentError } from './FrameParser.js';
4
+ import { ID3v2Parser } from './ID3v2Parser.js';
5
+ import { ID3v2Header } from './ID3v2Token.js';
6
+ /** Borrow the chunk payload; consume its remainder while leaving container padding to the caller. */
7
+ export async function parseEmbeddedID3v2(metadata, tokenizer, options, size) {
8
+ // Retain the metadata payload limit, including for caller-provided tokenizers.
9
+ validateAllocation(size, options);
10
+ if (size < ID3v2Header.len ||
11
+ (tokenizer.fileInfo.size !== undefined && size > tokenizer.fileInfo.size - tokenizer.position)) {
12
+ throw new EndOfStreamError();
13
+ }
14
+ const embeddedTokenizer = createTokenizerView(tokenizer, size);
15
+ try {
16
+ await new ID3v2Parser().parse(metadata, embeddedTokenizer, options);
17
+ await embeddedTokenizer.consumeRemainder();
18
+ }
19
+ catch (error) {
20
+ if (error instanceof TokenizerBoundaryError) {
21
+ throw new Id3v2ContentError(`Embedded ID3v2 read exceeds chunk boundary: ${error.message}`);
22
+ }
23
+ throw error;
24
+ }
25
+ finally {
26
+ // Closing the borrowed view never closes the container's input.
27
+ await embeddedTokenizer.close();
28
+ }
29
+ }
package/lib/index.d.ts CHANGED
@@ -15,8 +15,10 @@ export * from './core.js';
15
15
  export declare function parseStream(stream: Readable, fileInfo?: IFileInfo | string, options?: IOptions): Promise<IAudioMetadata>;
16
16
  /**
17
17
  * Parse audio from Node file
18
+ * Requires a regular file; symlinks to regular files are supported.
18
19
  * @param filePath - Media file to read meta-data from
19
20
  * @param options - Parsing options
20
21
  * @returns Metadata
22
+ * @throws {NotRegularFileError} If the opened filesystem object is not a regular file.
21
23
  */
22
24
  export declare function parseFile(filePath: string, options?: IOptions): Promise<IAudioMetadata>;
package/lib/index.js CHANGED
@@ -26,13 +26,18 @@ export async function parseStream(stream, fileInfo, options = {}) {
26
26
  }
27
27
  /**
28
28
  * Parse audio from Node file
29
+ * Requires a regular file; symlinks to regular files are supported.
29
30
  * @param filePath - Media file to read meta-data from
30
31
  * @param options - Parsing options
31
32
  * @returns Metadata
33
+ * @throws {NotRegularFileError} If the opened filesystem object is not a regular file.
32
34
  */
33
35
  export async function parseFile(filePath, options = {}) {
34
36
  debug(`parseFile: ${filePath}`);
35
- const fileTokenizer = await fromFile(filePath, getTokenizerOptions(options));
37
+ const fileTokenizer = await fromFile(filePath, {
38
+ ...getTokenizerOptions(options),
39
+ regularFileOnly: true
40
+ });
36
41
  const parserFactory = new ParserFactory();
37
42
  try {
38
43
  const parserLoader = parserFactory.findLoaderForExtension(filePath);