Borewit / music-metadata

Stream and file based music metadata parser for node. Supporting a wide range of audio and tag formats.
MIT License
893 stars 90 forks source link

`parseWebStream` not exported in Node.js entry point #2143

Closed Borewit closed 1 month ago

Borewit commented 1 month ago
          @Borewit Unless I'm missing something, it looks like parseWebStream is not being exported and thus cannot be used: https://github.com/Borewit/music-metadata/blob/v9.0.0/lib/index.ts#L11.

Furthermore, on use of this code:

const response = await fetch(`https://my/mp3/file`);
const metadata = await parseWebStream(response.body!, response.headers.get('content-type')!, {
  skipPostHeaders: true,
  includeChapters: true,
  skipCovers: true
});

I get this error:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stream' must be a byte stream. Received ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
    at new NodeError (node:internal/errors:405:5)
    at setupReadableStreamBYOBReader (node:internal/webstreams/readablestream:2155:11)
    at new ReadableStreamBYOBReader (node:internal/webstreams/readablestream:916:5)
    at ReadableStream.getReader (node:internal/webstreams/readablestream:352:12)
    at new WebStreamReader (file:///home/pcbowers/projects/hono/node_modules/.pnpm/peek-readable@5.1.1/node_modules/peek-readable/lib/WebStreamReader.js:12:30)
    at Module.fromWebStream (file:///home/pcbowers/projects/hono/node_modules/.pnpm/strtok3@7.1.0/node_modules/strtok3/lib/core.js:25:36)
    at Module.parseWebStream (file:///home/pcbowers/projects/hono/node_modules/.pnpm/music-metadata@9.0.0/node_modules/music-metadata/lib/core.js:29:39)
    at Array.eval (/home/pcbowers/projects/hono/src/index.ts:12:48)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getRequestListener.overrideGlobalObjects (file:///home/pcbowers/projects/hono/node_modules/.pnpm/@hono+vite-dev-server@0.13.0_hono@4.4.13/node_modules/@hono/vite-dev-server/dist/dev-server.js:69:32) {
  code: 'ERR_INVALID_ARG_VALUE'

I wish I knew more about it or else I would have debugged further! Leaving this here instead of on a new issue since I think fixing this would solve "avoid parsing entire file"

Originally posted by @pcbowers in https://github.com/Borewit/music-metadata/issues/2135#issuecomment-2224504220

Borewit commented 1 month ago

@pcbowers The ReadableStream must be indeed be a byte stream. Why fetch does not provide you one, I do not know.

To see a working Web stream in action, try: https://audio-tag-analyzer.netlify.app/

pcbowers commented 1 month ago

Hmm, don't we still need to export parseWebStream to make it usable?

https://github.com/Borewit/music-metadata/blob/v9.0.0/lib/index.ts#L11

Borewit commented 1 month ago

Hmm, don't we still need to export parseWebStream to make it usable?

https://github.com/Borewit/music-metadata/blob/v9.0.0/lib/index.ts#L11

I would say it would, good catch!