@remotion/media-parser 4.0.269 → 4.0.271

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.
Files changed (339) hide show
  1. package/dist/aac-codecprivate.js +6 -13
  2. package/dist/add-avc-profile-to-track.js +5 -9
  3. package/dist/buffer-iterator.js +8 -13
  4. package/dist/combine-uint8-arrays.js +1 -5
  5. package/dist/containers/aac/parse-aac.js +9 -13
  6. package/dist/containers/aac/types.js +1 -2
  7. package/dist/containers/avc/codec-string.js +1 -5
  8. package/dist/containers/avc/color.js +3 -9
  9. package/dist/containers/avc/create-sps-pps-data.js +5 -9
  10. package/dist/containers/avc/interpret-sps.js +7 -13
  11. package/dist/containers/avc/key.js +1 -5
  12. package/dist/containers/avc/parse-avc.js +3 -7
  13. package/dist/containers/avc/sps-and-pps.js +1 -5
  14. package/dist/containers/flac/get-block-size.js +1 -5
  15. package/dist/containers/flac/get-channel-count.d.ts +1 -1
  16. package/dist/containers/flac/get-channel-count.js +1 -5
  17. package/dist/containers/flac/get-duration-from-flac.js +1 -5
  18. package/dist/containers/flac/get-metadata-from-flac.js +1 -5
  19. package/dist/containers/flac/get-sample-rate.js +1 -5
  20. package/dist/containers/flac/parse-flac-frame.js +14 -19
  21. package/dist/containers/flac/parse-flac.js +15 -19
  22. package/dist/containers/flac/parse-header.js +1 -5
  23. package/dist/containers/flac/parse-metadata.js +1 -5
  24. package/dist/containers/flac/parse-streaminfo.js +3 -7
  25. package/dist/containers/flac/parse-unknown-block.js +1 -5
  26. package/dist/containers/flac/types.d.ts +2 -2
  27. package/dist/containers/flac/types.js +1 -2
  28. package/dist/containers/iso-base-media/base-media-box.js +1 -2
  29. package/dist/containers/iso-base-media/base-type.js +1 -2
  30. package/dist/containers/iso-base-media/esds/decoder-specific-config.js +1 -5
  31. package/dist/containers/iso-base-media/esds/esds-descriptors.js +5 -10
  32. package/dist/containers/iso-base-media/esds/esds.js +3 -7
  33. package/dist/containers/iso-base-media/ftyp.js +1 -5
  34. package/dist/containers/iso-base-media/get-actual-number-of-channels.js +4 -8
  35. package/dist/containers/iso-base-media/get-children.js +3 -7
  36. package/dist/containers/iso-base-media/get-keyframes.js +7 -11
  37. package/dist/containers/iso-base-media/get-moov-atom.js +22 -15
  38. package/dist/containers/iso-base-media/get-sample-positions-from-track.js +20 -24
  39. package/dist/containers/iso-base-media/get-video-codec-from-iso-track.d.ts +1 -1
  40. package/dist/containers/iso-base-media/get-video-codec-from-iso-track.js +3 -7
  41. package/dist/containers/iso-base-media/make-track.js +30 -34
  42. package/dist/containers/iso-base-media/mdat/mdat.js +16 -20
  43. package/dist/containers/iso-base-media/mdhd.js +1 -5
  44. package/dist/containers/iso-base-media/meta/hdlr.js +1 -5
  45. package/dist/containers/iso-base-media/meta/ilst.js +1 -5
  46. package/dist/containers/iso-base-media/moov/moov.js +3 -7
  47. package/dist/containers/iso-base-media/mvhd.js +7 -11
  48. package/dist/containers/iso-base-media/parse-boxes.js +5 -9
  49. package/dist/containers/iso-base-media/parse-icc-profile.js +4 -8
  50. package/dist/containers/iso-base-media/process-box.js +63 -67
  51. package/dist/containers/iso-base-media/stsd/av1c.js +1 -5
  52. package/dist/containers/iso-base-media/stsd/avcc.js +1 -5
  53. package/dist/containers/iso-base-media/stsd/colr.js +3 -7
  54. package/dist/containers/iso-base-media/stsd/ctts.js +1 -5
  55. package/dist/containers/iso-base-media/stsd/hvcc.js +3 -7
  56. package/dist/containers/iso-base-media/stsd/keys.js +1 -5
  57. package/dist/containers/iso-base-media/stsd/mebx.js +3 -7
  58. package/dist/containers/iso-base-media/stsd/pasp.js +1 -5
  59. package/dist/containers/iso-base-media/stsd/samples.js +8 -13
  60. package/dist/containers/iso-base-media/stsd/stco.js +1 -5
  61. package/dist/containers/iso-base-media/stsd/stsc.js +1 -5
  62. package/dist/containers/iso-base-media/stsd/stsd.js +3 -7
  63. package/dist/containers/iso-base-media/stsd/stss.js +1 -5
  64. package/dist/containers/iso-base-media/stsd/stsz.js +1 -5
  65. package/dist/containers/iso-base-media/stsd/stts.js +1 -5
  66. package/dist/containers/iso-base-media/tfdt.js +1 -5
  67. package/dist/containers/iso-base-media/tfhd.js +1 -5
  68. package/dist/containers/iso-base-media/tkhd.js +4 -8
  69. package/dist/containers/iso-base-media/to-date.js +1 -5
  70. package/dist/containers/iso-base-media/trak/trak.js +3 -7
  71. package/dist/containers/iso-base-media/traversal.d.ts +3 -2
  72. package/dist/containers/iso-base-media/traversal.js +42 -57
  73. package/dist/containers/iso-base-media/trun.js +2 -6
  74. package/dist/containers/iso-base-media/void-box.js +1 -2
  75. package/dist/containers/m3u/after-manifest-fetch.d.ts +8 -8
  76. package/dist/containers/m3u/after-manifest-fetch.js +33 -51
  77. package/dist/containers/m3u/fetch-m3u8-stream.d.ts +5 -2
  78. package/dist/containers/m3u/fetch-m3u8-stream.js +4 -12
  79. package/dist/containers/m3u/get-chunks.d.ts +1 -0
  80. package/dist/containers/m3u/get-chunks.js +6 -6
  81. package/dist/containers/m3u/get-duration-from-m3u.d.ts +2 -2
  82. package/dist/containers/m3u/get-duration-from-m3u.js +9 -8
  83. package/dist/containers/m3u/get-playlist.d.ts +6 -1
  84. package/dist/containers/m3u/get-playlist.js +19 -16
  85. package/dist/containers/m3u/get-streams.d.ts +14 -7
  86. package/dist/containers/m3u/get-streams.js +15 -18
  87. package/dist/containers/m3u/iterate-over-segment-files.d.ts +19 -0
  88. package/dist/containers/m3u/iterate-over-segment-files.js +106 -0
  89. package/dist/containers/m3u/m3u-child-stream.d.ts +0 -0
  90. package/dist/containers/m3u/m3u-child-stream.js +1 -0
  91. package/dist/containers/m3u/parse-directive.js +37 -10
  92. package/dist/containers/m3u/parse-m3u-manifest.js +3 -7
  93. package/dist/containers/m3u/parse-m3u-media-directive.d.ts +1 -0
  94. package/dist/containers/m3u/parse-m3u-media-directive.js +7 -7
  95. package/dist/containers/m3u/parse-m3u.js +18 -11
  96. package/dist/containers/m3u/parse-m3u8-text.js +3 -7
  97. package/dist/containers/m3u/parse-stream-inf.js +2 -7
  98. package/dist/containers/m3u/return-packets.d.ts +3 -2
  99. package/dist/containers/m3u/return-packets.js +92 -54
  100. package/dist/containers/m3u/run-over-m3u.d.ts +9 -0
  101. package/dist/containers/m3u/run-over-m3u.js +85 -0
  102. package/dist/containers/m3u/sample-sorter.d.ts +13 -0
  103. package/dist/containers/m3u/sample-sorter.js +60 -0
  104. package/dist/containers/m3u/select-stream.d.ts +10 -1
  105. package/dist/containers/m3u/select-stream.js +23 -7
  106. package/dist/containers/m3u/types.d.ts +15 -1
  107. package/dist/containers/m3u/types.js +1 -2
  108. package/dist/containers/mp3/get-duration.js +5 -9
  109. package/dist/containers/mp3/get-frame-length.js +2 -7
  110. package/dist/containers/mp3/get-metadata-from-mp3.d.ts +2 -2
  111. package/dist/containers/mp3/get-metadata-from-mp3.js +1 -5
  112. package/dist/containers/mp3/id3-v1.js +1 -5
  113. package/dist/containers/mp3/id3.js +1 -5
  114. package/dist/containers/mp3/parse-mp3.js +7 -11
  115. package/dist/containers/mp3/parse-mpeg-header.js +10 -14
  116. package/dist/containers/mp3/samples-per-mpeg-file.js +1 -5
  117. package/dist/containers/riff/expect-riff-box.js +11 -15
  118. package/dist/containers/riff/get-duration.js +7 -12
  119. package/dist/containers/riff/get-tracks-from-avi.js +20 -28
  120. package/dist/containers/riff/is-movi.js +1 -5
  121. package/dist/containers/riff/parse-avih.js +1 -5
  122. package/dist/containers/riff/parse-isft.js +1 -5
  123. package/dist/containers/riff/parse-list-box.js +3 -7
  124. package/dist/containers/riff/parse-movi.js +13 -18
  125. package/dist/containers/riff/parse-riff-body.js +9 -13
  126. package/dist/containers/riff/parse-riff-box.js +9 -13
  127. package/dist/containers/riff/parse-riff-header.js +1 -5
  128. package/dist/containers/riff/parse-riff.js +5 -9
  129. package/dist/containers/riff/parse-strf.js +1 -5
  130. package/dist/containers/riff/parse-strh.js +3 -7
  131. package/dist/containers/riff/parse-video-section.js +7 -11
  132. package/dist/containers/riff/riff-box.js +1 -2
  133. package/dist/containers/riff/timescale.js +1 -4
  134. package/dist/containers/riff/traversal.js +7 -15
  135. package/dist/containers/transport-stream/adts-header.js +6 -10
  136. package/dist/containers/transport-stream/boxes.js +1 -2
  137. package/dist/containers/transport-stream/discard-rest-of-packet.js +2 -7
  138. package/dist/containers/transport-stream/find-separator.js +1 -4
  139. package/dist/containers/transport-stream/get-tracks.js +7 -12
  140. package/dist/containers/transport-stream/handle-aac-packet.js +12 -16
  141. package/dist/containers/transport-stream/handle-avc-packet.js +22 -26
  142. package/dist/containers/transport-stream/next-pes-header-store.js +1 -5
  143. package/dist/containers/transport-stream/parse-packet.js +13 -17
  144. package/dist/containers/transport-stream/parse-pat.js +5 -10
  145. package/dist/containers/transport-stream/parse-pes.js +1 -5
  146. package/dist/containers/transport-stream/parse-pmt.js +3 -7
  147. package/dist/containers/transport-stream/parse-stream-packet.js +13 -17
  148. package/dist/containers/transport-stream/parse-transport-stream.js +5 -9
  149. package/dist/containers/transport-stream/process-stream-buffers.js +10 -15
  150. package/dist/containers/transport-stream/traversal.js +4 -10
  151. package/dist/containers/wav/get-duration-from-wav.js +3 -8
  152. package/dist/containers/wav/get-metadata-from-wav.d.ts +2 -2
  153. package/dist/containers/wav/get-metadata-from-wav.js +1 -5
  154. package/dist/containers/wav/parse-data.js +5 -9
  155. package/dist/containers/wav/parse-fmt.js +3 -7
  156. package/dist/containers/wav/parse-header.js +1 -5
  157. package/dist/containers/wav/parse-id3.js +1 -5
  158. package/dist/containers/wav/parse-list.js +10 -6
  159. package/dist/containers/wav/parse-video-section.js +3 -7
  160. package/dist/containers/wav/parse-wav.js +15 -19
  161. package/dist/containers/wav/types.d.ts +2 -2
  162. package/dist/containers/wav/types.js +1 -2
  163. package/dist/containers/webm/allowed-partial-segments.js +1 -4
  164. package/dist/containers/webm/av1-codec-private.js +3 -7
  165. package/dist/containers/webm/color.js +6 -10
  166. package/dist/containers/webm/description.js +6 -10
  167. package/dist/containers/webm/get-ready-tracks.js +13 -18
  168. package/dist/containers/webm/get-sample-from-block.js +12 -16
  169. package/dist/containers/webm/make-track.js +43 -48
  170. package/dist/containers/webm/parse-ebml.js +14 -19
  171. package/dist/containers/webm/parse-webm-header.js +3 -7
  172. package/dist/containers/webm/segments/all-segments.js +168 -173
  173. package/dist/containers/webm/segments/block-simple-block-flags.js +4 -8
  174. package/dist/containers/webm/segments/track-entry.js +1 -5
  175. package/dist/containers/webm/segments.js +9 -13
  176. package/dist/containers/webm/traversal.js +37 -67
  177. package/dist/convert-audio-or-video-sample.js +1 -5
  178. package/dist/download-and-parse-media.js +44 -46
  179. package/dist/emit-available-info.js +38 -38
  180. package/dist/emitter.js +1 -5
  181. package/dist/errors.d.ts +2 -17
  182. package/dist/errors.js +10 -30
  183. package/dist/esm/fetch.mjs +93 -67
  184. package/dist/esm/index.mjs +1189 -355
  185. package/dist/esm/node.mjs +59 -36
  186. package/dist/esm/universal.mjs +323 -0
  187. package/dist/esm/web-file.mjs +55 -43
  188. package/dist/esm/web.mjs +257 -0
  189. package/dist/esm/worker-server-entry.mjs +13056 -0
  190. package/dist/esm/worker-server.mjs +12914 -0
  191. package/dist/esm/worker-web-entry.mjs +12969 -0
  192. package/dist/esm/worker.mjs +439 -0
  193. package/dist/fetch.js +1 -17
  194. package/dist/file-types/bmp.js +3 -7
  195. package/dist/file-types/detect-file-type.js +24 -38
  196. package/dist/file-types/index.js +22 -26
  197. package/dist/file-types/jpeg.js +4 -9
  198. package/dist/file-types/pdf.js +3 -7
  199. package/dist/file-types/png.js +4 -9
  200. package/dist/file-types/webp.js +3 -7
  201. package/dist/forward-controller.js +1 -5
  202. package/dist/get-audio-codec.js +25 -38
  203. package/dist/get-container.d.ts +3 -3
  204. package/dist/get-container.js +5 -10
  205. package/dist/get-dimensions.js +8 -13
  206. package/dist/get-duration.js +27 -34
  207. package/dist/get-fields-from-callbacks.js +1 -5
  208. package/dist/get-fps.js +24 -34
  209. package/dist/get-is-hdr.js +5 -10
  210. package/dist/get-keyframes.js +6 -11
  211. package/dist/get-location.js +4 -9
  212. package/dist/get-number-of-audio-channels.js +2 -7
  213. package/dist/get-sample-aspect-ratio.js +17 -30
  214. package/dist/get-sample-positions-from-lpcm.js +5 -9
  215. package/dist/get-sample-positions.js +1 -5
  216. package/dist/get-sample-rate.js +2 -7
  217. package/dist/get-tracks.d.ts +5 -0
  218. package/dist/get-tracks.js +37 -44
  219. package/dist/get-video-codec.js +26 -34
  220. package/dist/has-all-info.js +33 -38
  221. package/dist/index.d.ts +44 -36
  222. package/dist/index.js +34 -47
  223. package/dist/init-video.d.ts +1 -1
  224. package/dist/init-video.js +47 -20
  225. package/dist/internal-parse-media.js +39 -41
  226. package/dist/is-audio-structure.d.ts +2 -2
  227. package/dist/is-audio-structure.js +1 -5
  228. package/dist/log.js +8 -12
  229. package/dist/make-hvc1-codec-strings.js +1 -5
  230. package/dist/media-parser-controller.js +7 -11
  231. package/dist/metadata/get-metadata.d.ts +4 -4
  232. package/dist/metadata/get-metadata.js +17 -22
  233. package/dist/metadata/metadata-from-iso.d.ts +3 -3
  234. package/dist/metadata/metadata-from-iso.js +12 -17
  235. package/dist/metadata/metadata-from-matroska.d.ts +2 -2
  236. package/dist/metadata/metadata-from-matroska.js +3 -7
  237. package/dist/metadata/metadata-from-riff.d.ts +2 -2
  238. package/dist/metadata/metadata-from-riff.js +3 -7
  239. package/dist/node-writer.js +1 -17
  240. package/dist/node.js +1 -17
  241. package/dist/options.d.ts +32 -25
  242. package/dist/options.js +1 -2
  243. package/dist/parse-media-on-browser-worker.d.ts +2 -0
  244. package/dist/parse-media-on-browser-worker.js +4 -0
  245. package/dist/parse-media-on-server-worker.d.ts +2 -0
  246. package/dist/parse-media-on-server-worker.js +4 -0
  247. package/dist/parse-media-on-web-worker.d.ts +2 -0
  248. package/dist/parse-media-on-web-worker.js +4 -0
  249. package/dist/parse-media-on-worker-entry.d.ts +2 -0
  250. package/dist/parse-media-on-worker-entry.js +269 -0
  251. package/dist/parse-media-on-worker.d.ts +2 -0
  252. package/dist/parse-media-on-worker.js +4 -0
  253. package/dist/parse-media.js +10 -12
  254. package/dist/parse-result.d.ts +3 -3
  255. package/dist/parse-result.js +1 -2
  256. package/dist/pause-signal.js +1 -5
  257. package/dist/perform-seek.js +6 -10
  258. package/dist/readers/fetch/get-body-and-reader.js +1 -5
  259. package/dist/readers/fetch/resolve-url.d.ts +1 -1
  260. package/dist/readers/fetch/resolve-url.js +1 -5
  261. package/dist/readers/from-fetch.d.ts +4 -1
  262. package/dist/readers/from-fetch.js +109 -94
  263. package/dist/readers/from-node.d.ts +4 -1
  264. package/dist/readers/from-node.js +58 -41
  265. package/dist/readers/from-web-file.d.ts +4 -1
  266. package/dist/readers/from-web-file.js +55 -49
  267. package/dist/readers/reader.d.ts +5 -1
  268. package/dist/readers/reader.js +1 -2
  269. package/dist/readers/universal.d.ts +2 -0
  270. package/dist/readers/universal.js +35 -0
  271. package/dist/readers/web.d.ts +2 -0
  272. package/dist/readers/web.js +22 -0
  273. package/dist/register-track.js +9 -15
  274. package/dist/remotion-license-acknowledge.js +4 -8
  275. package/dist/run-parse-iteration.js +26 -25
  276. package/dist/samples-from-moof.js +8 -12
  277. package/dist/skip.js +1 -5
  278. package/dist/state/aac-state.js +1 -5
  279. package/dist/state/can-skip-tracks.d.ts +2 -2
  280. package/dist/state/can-skip-tracks.js +3 -8
  281. package/dist/state/emitted-fields.js +1 -5
  282. package/dist/state/flac-state.js +1 -5
  283. package/dist/state/has-tracks-section.js +3 -7
  284. package/dist/state/images.js +1 -5
  285. package/dist/state/iso-base-media/cached-sample-positions.js +8 -13
  286. package/dist/state/iso-base-media/iso-state.js +5 -9
  287. package/dist/state/iso-base-media/moov-box.js +1 -5
  288. package/dist/state/keyframes.js +1 -5
  289. package/dist/state/last-eventloop-break.js +3 -7
  290. package/dist/state/m3u-state.d.ts +37 -16
  291. package/dist/state/m3u-state.js +98 -29
  292. package/dist/state/may-skip-video-data.js +3 -7
  293. package/dist/state/mp3.js +1 -5
  294. package/dist/state/need-samples-for-fields.js +1 -5
  295. package/dist/state/parser-state.d.ts +39 -33
  296. package/dist/state/parser-state.js +37 -41
  297. package/dist/state/riff.js +1 -5
  298. package/dist/state/sample-callbacks.js +8 -12
  299. package/dist/state/slow-duration-fps.js +1 -5
  300. package/dist/state/structure.d.ts +4 -4
  301. package/dist/state/structure.js +1 -5
  302. package/dist/state/transport-stream.js +3 -7
  303. package/dist/state/video-section.js +1 -5
  304. package/dist/state/webm.js +5 -9
  305. package/dist/throttled-progress.js +21 -14
  306. package/dist/truthy.js +1 -4
  307. package/dist/universal.d.ts +1 -0
  308. package/dist/universal.js +1 -0
  309. package/dist/version.d.ts +1 -1
  310. package/dist/version.js +1 -4
  311. package/dist/web-file.js +1 -17
  312. package/dist/web.d.ts +1 -0
  313. package/dist/web.js +1 -0
  314. package/dist/webcodec-sample-types.d.ts +6 -4
  315. package/dist/webcodec-sample-types.js +1 -2
  316. package/dist/worker/forward-controller.d.ts +3 -0
  317. package/dist/worker/forward-controller.js +20 -0
  318. package/dist/worker/serialize-error.d.ts +4 -0
  319. package/dist/worker/serialize-error.js +95 -0
  320. package/dist/worker/worker-types.d.ts +243 -0
  321. package/dist/worker/worker-types.js +1 -0
  322. package/dist/worker-bun-entry.d.ts +1 -0
  323. package/dist/worker-bun-entry.js +5 -0
  324. package/dist/worker-entry.d.ts +1 -0
  325. package/dist/worker-entry.js +5 -0
  326. package/dist/worker-server-entry.d.ts +1 -0
  327. package/dist/worker-server-entry.js +5 -0
  328. package/dist/worker-server.d.ts +2 -0
  329. package/dist/worker-server.js +381 -0
  330. package/dist/worker-web-entry.d.ts +1 -0
  331. package/dist/worker-web-entry.js +5 -0
  332. package/dist/worker.d.ts +2 -0
  333. package/dist/worker.js +267 -0
  334. package/dist/writers/node.js +16 -23
  335. package/dist/writers/writer.js +1 -2
  336. package/package.json +40 -21
  337. package/fetch.js +0 -2
  338. package/test.json +0 -663
  339. package/web-file.js +0 -2
@@ -1,21 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emitAvailableInfo = void 0;
4
- const get_streams_1 = require("./containers/m3u/get-streams");
5
- const get_audio_codec_1 = require("./get-audio-codec");
6
- const get_container_1 = require("./get-container");
7
- const get_dimensions_1 = require("./get-dimensions");
8
- const get_duration_1 = require("./get-duration");
9
- const get_fps_1 = require("./get-fps");
10
- const get_is_hdr_1 = require("./get-is-hdr");
11
- const get_keyframes_1 = require("./get-keyframes");
12
- const get_location_1 = require("./get-location");
13
- const get_number_of_audio_channels_1 = require("./get-number-of-audio-channels");
14
- const get_sample_rate_1 = require("./get-sample-rate");
15
- const get_tracks_1 = require("./get-tracks");
16
- const get_video_codec_1 = require("./get-video-codec");
17
- const get_metadata_1 = require("./metadata/get-metadata");
18
- const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name, mimeType, fieldsInReturnValue, }) => {
1
+ import { getM3uStreams } from './containers/m3u/get-streams';
2
+ import { getAudioCodec } from './get-audio-codec';
3
+ import { getContainer } from './get-container';
4
+ import { getDimensions } from './get-dimensions';
5
+ import { getDuration } from './get-duration';
6
+ import { getFps } from './get-fps';
7
+ import { getIsHdr } from './get-is-hdr';
8
+ import { getKeyframes } from './get-keyframes';
9
+ import { getLocation } from './get-location';
10
+ import { getNumberOfAudioChannels } from './get-number-of-audio-channels';
11
+ import { getSampleRate } from './get-sample-rate';
12
+ import { getTracks } from './get-tracks';
13
+ import { getVideoCodec } from './get-video-codec';
14
+ import { getMetadata } from './metadata/get-metadata';
15
+ export const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name, mimeType, fieldsInReturnValue, }) => {
19
16
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
20
17
  const keys = Object.keys(hasInfo);
21
18
  const { emittedFields } = state;
@@ -33,7 +30,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
33
30
  if (key === 'durationInSeconds') {
34
31
  if (hasInfo.durationInSeconds) {
35
32
  if (!emittedFields.durationInSeconds) {
36
- const durationInSeconds = (0, get_duration_1.getDuration)(state);
33
+ const durationInSeconds = getDuration(state);
37
34
  await ((_b = callbacks.onDurationInSeconds) === null || _b === void 0 ? void 0 : _b.call(callbacks, durationInSeconds));
38
35
  if (fieldsInReturnValue.durationInSeconds) {
39
36
  returnValue.durationInSeconds = durationInSeconds;
@@ -46,7 +43,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
46
43
  if (key === 'slowDurationInSeconds') {
47
44
  if (hasInfo.slowDurationInSeconds &&
48
45
  !emittedFields.slowDurationInSeconds) {
49
- const slowDurationInSeconds = (_c = (0, get_duration_1.getDuration)(state)) !== null && _c !== void 0 ? _c : state.slowDurationAndFps.getSlowDurationInSeconds();
46
+ const slowDurationInSeconds = (_c = getDuration(state)) !== null && _c !== void 0 ? _c : state.slowDurationAndFps.getSlowDurationInSeconds();
50
47
  await ((_d = callbacks.onSlowDurationInSeconds) === null || _d === void 0 ? void 0 : _d.call(callbacks, slowDurationInSeconds));
51
48
  if (fieldsInReturnValue.slowDurationInSeconds) {
52
49
  returnValue.slowDurationInSeconds = slowDurationInSeconds;
@@ -58,7 +55,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
58
55
  if (key === 'fps') {
59
56
  if (hasInfo.fps) {
60
57
  if (!emittedFields.fps) {
61
- const fps = (0, get_fps_1.getFps)(state);
58
+ const fps = getFps(state);
62
59
  await ((_e = callbacks.onFps) === null || _e === void 0 ? void 0 : _e.call(callbacks, fps));
63
60
  if (fieldsInReturnValue.fps) {
64
61
  returnValue.fps = fps;
@@ -66,7 +63,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
66
63
  emittedFields.fps = true;
67
64
  }
68
65
  if (!emittedFields.slowFps) {
69
- const fps = (0, get_fps_1.getFps)(state);
66
+ const fps = getFps(state);
70
67
  if (fps) {
71
68
  await ((_f = callbacks.onSlowFps) === null || _f === void 0 ? void 0 : _f.call(callbacks, fps));
72
69
  if (fieldsInReturnValue.slowFps) {
@@ -92,7 +89,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
92
89
  }
93
90
  if (key === 'dimensions') {
94
91
  if (hasInfo.dimensions && !emittedFields.dimensions) {
95
- const dimensionsQueried = (0, get_dimensions_1.getDimensions)(state);
92
+ const dimensionsQueried = getDimensions(state);
96
93
  const dimensions = dimensionsQueried === null
97
94
  ? null
98
95
  : {
@@ -109,7 +106,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
109
106
  }
110
107
  if (key === 'unrotatedDimensions') {
111
108
  if (hasInfo.unrotatedDimensions && !emittedFields.unrotatedDimensions) {
112
- const dimensionsQueried = (0, get_dimensions_1.getDimensions)(state);
109
+ const dimensionsQueried = getDimensions(state);
113
110
  const unrotatedDimensions = dimensionsQueried === null
114
111
  ? null
115
112
  : {
@@ -126,7 +123,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
126
123
  }
127
124
  if (key === 'rotation') {
128
125
  if (hasInfo.rotation && !emittedFields.rotation) {
129
- const dimensionsQueried = (0, get_dimensions_1.getDimensions)(state);
126
+ const dimensionsQueried = getDimensions(state);
130
127
  const rotation = (_k = dimensionsQueried === null || dimensionsQueried === void 0 ? void 0 : dimensionsQueried.rotation) !== null && _k !== void 0 ? _k : 0;
131
128
  await ((_l = callbacks.onRotation) === null || _l === void 0 ? void 0 : _l.call(callbacks, rotation));
132
129
  if (fieldsInReturnValue.rotation) {
@@ -138,7 +135,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
138
135
  }
139
136
  if (key === 'videoCodec') {
140
137
  if (!emittedFields.videoCodec && hasInfo.videoCodec) {
141
- const videoCodec = (0, get_video_codec_1.getVideoCodec)(state);
138
+ const videoCodec = getVideoCodec(state);
142
139
  await ((_m = callbacks.onVideoCodec) === null || _m === void 0 ? void 0 : _m.call(callbacks, videoCodec));
143
140
  if (fieldsInReturnValue.videoCodec) {
144
141
  returnValue.videoCodec = videoCodec;
@@ -149,7 +146,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
149
146
  }
150
147
  if (key === 'audioCodec') {
151
148
  if (!emittedFields.audioCodec && hasInfo.audioCodec) {
152
- const audioCodec = (0, get_audio_codec_1.getAudioCodec)(state);
149
+ const audioCodec = getAudioCodec(state);
153
150
  await ((_o = callbacks.onAudioCodec) === null || _o === void 0 ? void 0 : _o.call(callbacks, audioCodec));
154
151
  if (fieldsInReturnValue.audioCodec) {
155
152
  returnValue.audioCodec = audioCodec;
@@ -160,7 +157,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
160
157
  }
161
158
  if (key === 'tracks') {
162
159
  if (!emittedFields.tracks && hasInfo.tracks) {
163
- const { videoTracks, audioTracks } = (0, get_tracks_1.getTracks)(state);
160
+ const { videoTracks, audioTracks } = getTracks(state);
164
161
  await ((_p = callbacks.onTracks) === null || _p === void 0 ? void 0 : _p.call(callbacks, { videoTracks, audioTracks }));
165
162
  if (fieldsInReturnValue.tracks) {
166
163
  returnValue.tracks = { videoTracks, audioTracks };
@@ -212,7 +209,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
212
209
  }
213
210
  if (key === 'isHdr') {
214
211
  if (!returnValue.isHdr && hasInfo.isHdr) {
215
- const isHdr = (0, get_is_hdr_1.getIsHdr)(state);
212
+ const isHdr = getIsHdr(state);
216
213
  await ((_t = callbacks.onIsHdr) === null || _t === void 0 ? void 0 : _t.call(callbacks, isHdr));
217
214
  if (fieldsInReturnValue.isHdr) {
218
215
  returnValue.isHdr = isHdr;
@@ -223,7 +220,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
223
220
  }
224
221
  if (key === 'container') {
225
222
  if (!returnValue.container && hasInfo.container) {
226
- const container = (0, get_container_1.getContainer)(state.getStructure());
223
+ const container = getContainer(state.getStructure());
227
224
  await ((_u = callbacks.onContainer) === null || _u === void 0 ? void 0 : _u.call(callbacks, container));
228
225
  if (fieldsInReturnValue.container) {
229
226
  returnValue.container = container;
@@ -234,7 +231,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
234
231
  }
235
232
  if (key === 'metadata') {
236
233
  if (!emittedFields.metadata && hasInfo.metadata) {
237
- const metadata = (0, get_metadata_1.getMetadata)(state);
234
+ const metadata = getMetadata(state);
238
235
  await ((_v = callbacks.onMetadata) === null || _v === void 0 ? void 0 : _v.call(callbacks, metadata));
239
236
  if (fieldsInReturnValue.metadata) {
240
237
  returnValue.metadata = metadata;
@@ -245,7 +242,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
245
242
  }
246
243
  if (key === 'location') {
247
244
  if (!emittedFields.location && hasInfo.location) {
248
- const location = (0, get_location_1.getLocation)(state);
245
+ const location = getLocation(state);
249
246
  await ((_w = callbacks.onLocation) === null || _w === void 0 ? void 0 : _w.call(callbacks, location));
250
247
  if (fieldsInReturnValue.location) {
251
248
  returnValue.location = location;
@@ -299,9 +296,9 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
299
296
  }
300
297
  if (key === 'keyframes') {
301
298
  if (!emittedFields.keyframes && hasInfo.keyframes) {
302
- await ((_1 = callbacks.onKeyframes) === null || _1 === void 0 ? void 0 : _1.call(callbacks, (0, get_keyframes_1.getKeyframes)(state)));
299
+ await ((_1 = callbacks.onKeyframes) === null || _1 === void 0 ? void 0 : _1.call(callbacks, getKeyframes(state)));
303
300
  if (fieldsInReturnValue.keyframes) {
304
- returnValue.keyframes = (0, get_keyframes_1.getKeyframes)(state);
301
+ returnValue.keyframes = getKeyframes(state);
305
302
  }
306
303
  emittedFields.keyframes = true;
307
304
  }
@@ -319,7 +316,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
319
316
  }
320
317
  if (key === 'sampleRate') {
321
318
  if (!emittedFields.sampleRate && hasInfo.sampleRate) {
322
- const sampleRate = (0, get_sample_rate_1.getSampleRate)(state);
319
+ const sampleRate = getSampleRate(state);
323
320
  await ((_3 = callbacks.onSampleRate) === null || _3 === void 0 ? void 0 : _3.call(callbacks, sampleRate));
324
321
  if (fieldsInReturnValue.sampleRate) {
325
322
  returnValue.sampleRate = sampleRate;
@@ -331,7 +328,7 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
331
328
  if (key === 'numberOfAudioChannels') {
332
329
  if (!emittedFields.numberOfAudioChannels &&
333
330
  hasInfo.numberOfAudioChannels) {
334
- const numberOfAudioChannels = (0, get_number_of_audio_channels_1.getNumberOfAudioChannels)(state);
331
+ const numberOfAudioChannels = getNumberOfAudioChannels(state);
335
332
  await ((_4 = callbacks.onNumberOfAudioChannels) === null || _4 === void 0 ? void 0 : _4.call(callbacks, numberOfAudioChannels));
336
333
  if (fieldsInReturnValue.numberOfAudioChannels) {
337
334
  returnValue.numberOfAudioChannels = numberOfAudioChannels;
@@ -342,7 +339,11 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
342
339
  }
343
340
  if (key === 'm3uStreams') {
344
341
  if (!emittedFields.m3uStreams && hasInfo.m3uStreams) {
345
- const streams = (0, get_streams_1.getM3uStreams)(state.getStructureOrNull(), typeof state.src === 'string' ? state.src : null);
342
+ const streams = getM3uStreams({
343
+ structure: state.getStructureOrNull(),
344
+ originalSrc: state.src,
345
+ readerInterface: state.readerInterface,
346
+ });
346
347
  await ((_5 = callbacks.onM3uStreams) === null || _5 === void 0 ? void 0 : _5.call(callbacks, streams));
347
348
  if (fieldsInReturnValue.m3uStreams) {
348
349
  returnValue.m3uStreams = streams;
@@ -354,4 +355,3 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
354
355
  throw new Error(`Unhandled key: ${key}`);
355
356
  }
356
357
  };
357
- exports.emitAvailableInfo = emitAvailableInfo;
package/dist/emitter.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MediaParserEmitter = void 0;
4
- class MediaParserEmitter {
1
+ export class MediaParserEmitter {
5
2
  constructor() {
6
3
  this.listeners = {
7
4
  pause: [],
@@ -30,4 +27,3 @@ class MediaParserEmitter {
30
27
  });
31
28
  }
32
29
  }
33
- exports.MediaParserEmitter = MediaParserEmitter;
package/dist/errors.d.ts CHANGED
@@ -9,8 +9,8 @@ export declare class IsAGifError extends Error {
9
9
  fileName: string | null;
10
10
  });
11
11
  }
12
- type ImageType = 'png' | 'jpeg' | 'bmp' | 'webp';
13
- type Dimensions = {
12
+ export type ImageType = 'png' | 'jpeg' | 'bmp' | 'webp';
13
+ export type Dimensions = {
14
14
  width: number;
15
15
  height: number;
16
16
  };
@@ -51,22 +51,7 @@ export declare class IsAnUnsupportedFileTypeError extends Error {
51
51
  fileName: string | null;
52
52
  });
53
53
  }
54
- type UnsupportedAudioType = never;
55
- export declare class IsAnUnsupportedAudioTypeError extends Error {
56
- mimeType: string | null;
57
- sizeInBytes: number | null;
58
- fileName: string | null;
59
- audioType: UnsupportedAudioType | null;
60
- constructor({ message, mimeType, sizeInBytes, fileName, audioType, }: {
61
- message: string;
62
- mimeType: string | null;
63
- sizeInBytes: number | null;
64
- fileName: string | null;
65
- audioType: UnsupportedAudioType | null;
66
- });
67
- }
68
54
  export declare class MediaParserAbortError extends Error {
69
55
  constructor(message: string);
70
56
  }
71
57
  export declare const hasBeenAborted: (error: unknown) => error is MediaParserAbortError;
72
- export {};
package/dist/errors.js CHANGED
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasBeenAborted = exports.MediaParserAbortError = exports.IsAnUnsupportedAudioTypeError = exports.IsAnUnsupportedFileTypeError = exports.IsAPdfError = exports.IsAnImageError = exports.IsAGifError = void 0;
4
- class IsAGifError extends Error {
1
+ export class IsAGifError extends Error {
5
2
  constructor({ message, mimeType, sizeInBytes, fileName, }) {
6
3
  super(message);
4
+ this.name = 'IsAGifError';
7
5
  this.fileName = 'IsAGifError';
8
6
  this.mimeType = mimeType;
9
7
  this.sizeInBytes = sizeInBytes;
@@ -13,8 +11,7 @@ class IsAGifError extends Error {
13
11
  }
14
12
  }
15
13
  }
16
- exports.IsAGifError = IsAGifError;
17
- class IsAnImageError extends Error {
14
+ export class IsAnImageError extends Error {
18
15
  constructor({ dimensions, imageType, message, mimeType, sizeInBytes, fileName, }) {
19
16
  super(message);
20
17
  this.name = 'IsAnImageError';
@@ -28,8 +25,7 @@ class IsAnImageError extends Error {
28
25
  }
29
26
  }
30
27
  }
31
- exports.IsAnImageError = IsAnImageError;
32
- class IsAPdfError extends Error {
28
+ export class IsAPdfError extends Error {
33
29
  constructor({ message, mimeType, sizeInBytes, fileName, }) {
34
30
  super(message);
35
31
  this.name = 'IsAPdfError';
@@ -41,8 +37,7 @@ class IsAPdfError extends Error {
41
37
  }
42
38
  }
43
39
  }
44
- exports.IsAPdfError = IsAPdfError;
45
- class IsAnUnsupportedFileTypeError extends Error {
40
+ export class IsAnUnsupportedFileTypeError extends Error {
46
41
  constructor({ message, mimeType, sizeInBytes, fileName, }) {
47
42
  super(message);
48
43
  this.name = 'IsAnUnsupportedFileTypeError';
@@ -54,30 +49,15 @@ class IsAnUnsupportedFileTypeError extends Error {
54
49
  }
55
50
  }
56
51
  }
57
- exports.IsAnUnsupportedFileTypeError = IsAnUnsupportedFileTypeError;
58
- class IsAnUnsupportedAudioTypeError extends Error {
59
- constructor({ message, mimeType, sizeInBytes, fileName, audioType, }) {
60
- super(message);
61
- this.name = 'IsAnUnsupportedAudioTypeError';
62
- this.mimeType = mimeType;
63
- this.sizeInBytes = sizeInBytes;
64
- this.fileName = fileName;
65
- this.audioType = audioType;
66
- if (Error.captureStackTrace) {
67
- Error.captureStackTrace(this, IsAnUnsupportedAudioTypeError);
68
- }
69
- }
70
- }
71
- exports.IsAnUnsupportedAudioTypeError = IsAnUnsupportedAudioTypeError;
72
- class MediaParserAbortError extends Error {
52
+ export class MediaParserAbortError extends Error {
73
53
  constructor(message) {
74
54
  super(message);
75
55
  this.name = 'MediaParserAbortError';
76
56
  this.cause = undefined;
77
57
  }
78
58
  }
79
- exports.MediaParserAbortError = MediaParserAbortError;
80
- const hasBeenAborted = (error) => {
81
- return error instanceof MediaParserAbortError;
59
+ export const hasBeenAborted = (error) => {
60
+ return (error instanceof MediaParserAbortError ||
61
+ // On worker it is not the same instance, but same name
62
+ error.name === 'MediaParserAbortError');
82
63
  };
83
- exports.hasBeenAborted = hasBeenAborted;
@@ -80,89 +80,115 @@ function parseContentRange(input) {
80
80
  return range;
81
81
  }
82
82
  var validateContentRangeAndDetectIfSupported = ({
83
- actualRange,
83
+ requestedRange,
84
84
  parsedContentRange,
85
85
  statusCode
86
86
  }) => {
87
87
  if (statusCode === 206) {
88
88
  return { supportsContentRange: true };
89
89
  }
90
- if (typeof actualRange === "number" && parsedContentRange?.start !== actualRange) {
91
- if (actualRange === 0) {
90
+ if (typeof requestedRange === "number" && parsedContentRange?.start !== requestedRange) {
91
+ if (requestedRange === 0) {
92
92
  return { supportsContentRange: false };
93
93
  }
94
- throw new Error(`Range header (${actualRange}) does not match content-range header (${parsedContentRange?.start})`);
94
+ throw new Error(`Range header (${requestedRange}) does not match content-range header (${parsedContentRange?.start})`);
95
95
  }
96
- if (actualRange !== null && typeof actualRange !== "number" && (parsedContentRange?.start !== actualRange[0] || parsedContentRange?.end !== actualRange[1])) {
97
- throw new Error(`Range header (${actualRange}) does not match content-range header (${parsedContentRange?.start})`);
96
+ if (requestedRange !== null && typeof requestedRange !== "number" && (parsedContentRange?.start !== requestedRange[0] || parsedContentRange?.end !== requestedRange[1])) {
97
+ throw new Error(`Range header (${requestedRange}) does not match content-range header (${parsedContentRange?.start})`);
98
98
  }
99
99
  return { supportsContentRange: true };
100
100
  };
101
- var fetchReader = {
102
- read: async ({ src, range, controller }) => {
103
- if (typeof src !== "string") {
104
- throw new Error("src must be a string when using `fetchReader`");
105
- }
106
- const resolvedUrl = resolveUrl(src);
107
- const resolvedUrlString = resolvedUrl.toString();
108
- if (!resolvedUrlString.startsWith("https://") && !resolvedUrlString.startsWith("blob:") && !resolvedUrlString.startsWith("http://")) {
109
- return Promise.reject(new Error(`${resolvedUrlString} is not a URL - needs to start with http:// or https:// or blob:. If you want to read a local file, pass \`reader: nodeReader\` to parseMedia().`));
110
- }
111
- const ownController = new AbortController;
112
- const cache = typeof navigator !== "undefined" && navigator.userAgent.includes("Cloudflare-Workers") ? undefined : "no-store";
113
- const actualRange = range === null ? 0 : range;
114
- const asString = typeof resolvedUrl === "string" ? resolvedUrl : resolvedUrl.pathname;
115
- const requestWithoutRange = asString.endsWith(".m3u8");
116
- const canLiveWithoutContentLength = asString.endsWith(".m3u8") || asString.endsWith(".ts");
117
- const headers = actualRange === 0 && requestWithoutRange ? {} : typeof actualRange === "number" ? {
118
- Range: `bytes=${actualRange}-`
119
- } : {
120
- Range: `bytes=${`${actualRange[0]}-${actualRange[1]}`}`
121
- };
122
- const res = await fetch(resolvedUrl, {
123
- headers,
124
- signal: ownController.signal,
125
- cache
126
- });
127
- const contentRange = res.headers.get("content-range");
128
- const parsedContentRange = contentRange ? parseContentRange(contentRange) : null;
129
- const { supportsContentRange } = validateContentRangeAndDetectIfSupported({
130
- actualRange,
131
- parsedContentRange,
132
- statusCode: res.status
133
- });
101
+ var fetchReadContent = async ({
102
+ src,
103
+ range,
104
+ controller
105
+ }) => {
106
+ if (typeof src !== "string" && src instanceof URL === false) {
107
+ throw new Error("src must be a string when using `fetchReader`");
108
+ }
109
+ const resolvedUrl = resolveUrl(src);
110
+ const resolvedUrlString = resolvedUrl.toString();
111
+ if (!resolvedUrlString.startsWith("https://") && !resolvedUrlString.startsWith("blob:") && !resolvedUrlString.startsWith("http://")) {
112
+ return Promise.reject(new Error(`${resolvedUrlString} is not a URL - needs to start with http:// or https:// or blob:. If you want to read a local file, pass \`reader: nodeReader\` to parseMedia().`));
113
+ }
114
+ const ownController = new AbortController;
115
+ const cache = typeof navigator !== "undefined" && navigator.userAgent.includes("Cloudflare-Workers") ? undefined : "no-store";
116
+ const requestedRange = range === null ? 0 : range;
117
+ const asString = typeof resolvedUrl === "string" ? resolvedUrl : resolvedUrl.pathname;
118
+ const requestWithoutRange = asString.endsWith(".m3u8");
119
+ const canLiveWithoutContentLength = asString.endsWith(".m3u8") || asString.endsWith(".ts");
120
+ const headers = requestedRange === 0 && requestWithoutRange ? {} : typeof requestedRange === "number" ? {
121
+ Range: `bytes=${requestedRange}-`
122
+ } : {
123
+ Range: `bytes=${`${requestedRange[0]}-${requestedRange[1]}`}`
124
+ };
125
+ const res = await fetch(resolvedUrl, {
126
+ headers,
127
+ signal: ownController.signal,
128
+ cache
129
+ });
130
+ const contentRange = res.headers.get("content-range");
131
+ const parsedContentRange = contentRange ? parseContentRange(contentRange) : null;
132
+ const { supportsContentRange } = validateContentRangeAndDetectIfSupported({
133
+ requestedRange,
134
+ parsedContentRange,
135
+ statusCode: res.status
136
+ });
137
+ controller._internals.signal.addEventListener("abort", () => {
138
+ ownController.abort(new MediaParserAbortError("Aborted by user"));
139
+ }, { once: true });
140
+ if (res.status.toString().startsWith("4") || res.status.toString().startsWith("5")) {
141
+ throw new Error(`Server returned status code ${res.status} for ${src} and range ${requestedRange}`);
142
+ }
143
+ const contentDisposition = res.headers.get("content-disposition");
144
+ const name = contentDisposition?.match(/filename="([^"]+)"/)?.[1];
145
+ const fallbackName = src.toString().split("/").pop();
146
+ const { contentLength, needsContentRange, reader } = await getLengthAndReader({
147
+ canLiveWithoutContentLength,
148
+ res,
149
+ ownController,
150
+ requestedWithoutRange: requestWithoutRange
151
+ });
152
+ if (controller) {
134
153
  controller._internals.signal.addEventListener("abort", () => {
135
- ownController.abort(new MediaParserAbortError("Aborted by user"));
154
+ reader.reader.cancel().catch(() => {
155
+ });
136
156
  }, { once: true });
137
- if (res.status.toString().startsWith("4") || res.status.toString().startsWith("5")) {
138
- throw new Error(`Server returned status code ${res.status} for ${src} and range ${actualRange}`);
139
- }
140
- const contentDisposition = res.headers.get("content-disposition");
141
- const name = contentDisposition?.match(/filename="([^"]+)"/)?.[1];
142
- const fallbackName = src.split("/").pop();
143
- const { contentLength, needsContentRange, reader } = await getLengthAndReader({
144
- canLiveWithoutContentLength,
145
- res,
146
- ownController,
147
- requestedWithoutRange: requestWithoutRange
148
- });
149
- if (controller) {
150
- controller._internals.signal.addEventListener("abort", () => {
151
- reader.reader.cancel().catch(() => {
152
- });
153
- }, { once: true });
154
- }
155
- return {
156
- reader,
157
- contentLength,
158
- contentType: res.headers.get("content-type"),
159
- name: name ?? fallbackName,
160
- supportsContentRange,
161
- needsContentRange
162
- };
163
157
  }
158
+ return {
159
+ reader,
160
+ contentLength,
161
+ contentType: res.headers.get("content-type"),
162
+ name: name ?? fallbackName,
163
+ supportsContentRange,
164
+ needsContentRange
165
+ };
166
+ };
167
+ var fetchReadWholeAsText = async (src) => {
168
+ if (typeof src !== "string" && src instanceof URL === false) {
169
+ throw new Error("src must be a string when using `fetchReader`");
170
+ }
171
+ const res = await fetch(src);
172
+ if (!res.ok) {
173
+ throw new Error(`Failed to fetch ${src} (HTTP code: ${res.status})`);
174
+ }
175
+ return res.text();
176
+ };
177
+ var fetchCreateAdjacentFileSource = (relativePath, src) => {
178
+ if (typeof src !== "string" && src instanceof URL === false) {
179
+ throw new Error("src must be a string or URL when using `fetchReader`");
180
+ }
181
+ return new URL(relativePath, src).toString();
182
+ };
183
+ var fetchReader = {
184
+ read: fetchReadContent,
185
+ readWholeAsText: fetchReadWholeAsText,
186
+ createAdjacentFileSource: fetchCreateAdjacentFileSource
164
187
  };
165
188
  export {
166
189
  parseContentRange,
167
- fetchReader
190
+ fetchReader,
191
+ fetchReadWholeAsText,
192
+ fetchReadContent,
193
+ fetchCreateAdjacentFileSource
168
194
  };