@remotion/media-parser 4.0.270 → 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.
- package/dist/aac-codecprivate.js +6 -13
- package/dist/add-avc-profile-to-track.js +5 -9
- package/dist/buffer-iterator.js +8 -13
- package/dist/combine-uint8-arrays.js +1 -5
- package/dist/containers/aac/parse-aac.js +9 -13
- package/dist/containers/aac/types.js +1 -2
- package/dist/containers/avc/codec-string.js +1 -5
- package/dist/containers/avc/color.js +3 -9
- package/dist/containers/avc/create-sps-pps-data.js +5 -9
- package/dist/containers/avc/interpret-sps.js +7 -13
- package/dist/containers/avc/key.js +1 -5
- package/dist/containers/avc/parse-avc.js +3 -7
- package/dist/containers/avc/sps-and-pps.js +1 -5
- package/dist/containers/flac/get-block-size.js +1 -5
- package/dist/containers/flac/get-channel-count.js +1 -5
- package/dist/containers/flac/get-duration-from-flac.js +1 -5
- package/dist/containers/flac/get-metadata-from-flac.js +1 -5
- package/dist/containers/flac/get-sample-rate.js +1 -5
- package/dist/containers/flac/parse-flac-frame.js +14 -19
- package/dist/containers/flac/parse-flac.js +15 -19
- package/dist/containers/flac/parse-header.js +1 -5
- package/dist/containers/flac/parse-metadata.js +1 -5
- package/dist/containers/flac/parse-streaminfo.js +3 -7
- package/dist/containers/flac/parse-unknown-block.js +1 -5
- package/dist/containers/flac/types.d.ts +2 -2
- package/dist/containers/flac/types.js +1 -2
- package/dist/containers/iso-base-media/base-media-box.js +1 -2
- package/dist/containers/iso-base-media/base-type.js +1 -2
- package/dist/containers/iso-base-media/esds/decoder-specific-config.js +1 -5
- package/dist/containers/iso-base-media/esds/esds-descriptors.js +5 -10
- package/dist/containers/iso-base-media/esds/esds.js +3 -7
- package/dist/containers/iso-base-media/ftyp.js +1 -5
- package/dist/containers/iso-base-media/get-actual-number-of-channels.js +4 -8
- package/dist/containers/iso-base-media/get-children.js +3 -7
- package/dist/containers/iso-base-media/get-keyframes.js +7 -11
- package/dist/containers/iso-base-media/get-moov-atom.js +21 -15
- package/dist/containers/iso-base-media/get-sample-positions-from-track.js +20 -24
- package/dist/containers/iso-base-media/get-video-codec-from-iso-track.d.ts +1 -1
- package/dist/containers/iso-base-media/get-video-codec-from-iso-track.js +3 -7
- package/dist/containers/iso-base-media/make-track.js +30 -34
- package/dist/containers/iso-base-media/mdat/mdat.js +16 -20
- package/dist/containers/iso-base-media/mdhd.js +1 -5
- package/dist/containers/iso-base-media/meta/hdlr.js +1 -5
- package/dist/containers/iso-base-media/meta/ilst.js +1 -5
- package/dist/containers/iso-base-media/moov/moov.js +3 -7
- package/dist/containers/iso-base-media/mvhd.js +7 -11
- package/dist/containers/iso-base-media/parse-boxes.js +5 -9
- package/dist/containers/iso-base-media/parse-icc-profile.js +4 -8
- package/dist/containers/iso-base-media/process-box.js +63 -67
- package/dist/containers/iso-base-media/stsd/av1c.js +1 -5
- package/dist/containers/iso-base-media/stsd/avcc.js +1 -5
- package/dist/containers/iso-base-media/stsd/colr.js +3 -7
- package/dist/containers/iso-base-media/stsd/ctts.js +1 -5
- package/dist/containers/iso-base-media/stsd/hvcc.js +3 -7
- package/dist/containers/iso-base-media/stsd/keys.js +1 -5
- package/dist/containers/iso-base-media/stsd/mebx.js +3 -7
- package/dist/containers/iso-base-media/stsd/pasp.js +1 -5
- package/dist/containers/iso-base-media/stsd/samples.js +8 -13
- package/dist/containers/iso-base-media/stsd/stco.js +1 -5
- package/dist/containers/iso-base-media/stsd/stsc.js +1 -5
- package/dist/containers/iso-base-media/stsd/stsd.js +3 -7
- package/dist/containers/iso-base-media/stsd/stss.js +1 -5
- package/dist/containers/iso-base-media/stsd/stsz.js +1 -5
- package/dist/containers/iso-base-media/stsd/stts.js +1 -5
- package/dist/containers/iso-base-media/tfdt.js +1 -5
- package/dist/containers/iso-base-media/tfhd.js +1 -5
- package/dist/containers/iso-base-media/tkhd.js +4 -8
- package/dist/containers/iso-base-media/to-date.js +1 -5
- package/dist/containers/iso-base-media/trak/trak.js +3 -7
- package/dist/containers/iso-base-media/traversal.d.ts +3 -2
- package/dist/containers/iso-base-media/traversal.js +42 -57
- package/dist/containers/iso-base-media/trun.js +2 -6
- package/dist/containers/iso-base-media/void-box.js +1 -2
- package/dist/containers/m3u/after-manifest-fetch.d.ts +5 -3
- package/dist/containers/m3u/after-manifest-fetch.js +13 -17
- package/dist/containers/m3u/fetch-m3u8-stream.d.ts +5 -1
- package/dist/containers/m3u/fetch-m3u8-stream.js +4 -12
- package/dist/containers/m3u/get-chunks.d.ts +1 -0
- package/dist/containers/m3u/get-chunks.js +6 -6
- package/dist/containers/m3u/get-duration-from-m3u.js +4 -8
- package/dist/containers/m3u/get-playlist.js +6 -12
- package/dist/containers/m3u/get-streams.d.ts +11 -5
- package/dist/containers/m3u/get-streams.js +5 -15
- package/dist/containers/m3u/iterate-over-segment-files.d.ts +19 -0
- package/dist/containers/m3u/iterate-over-segment-files.js +106 -0
- package/dist/containers/m3u/parse-directive.js +10 -10
- package/dist/containers/m3u/parse-m3u-manifest.js +3 -7
- package/dist/containers/m3u/parse-m3u-media-directive.d.ts +1 -0
- package/dist/containers/m3u/parse-m3u-media-directive.js +7 -7
- package/dist/containers/m3u/parse-m3u.js +13 -13
- package/dist/containers/m3u/parse-m3u8-text.js +3 -7
- package/dist/containers/m3u/parse-stream-inf.js +2 -7
- package/dist/containers/m3u/return-packets.d.ts +1 -1
- package/dist/containers/m3u/return-packets.js +14 -5
- package/dist/containers/m3u/run-over-m3u.js +10 -13
- package/dist/containers/m3u/sample-sorter.js +4 -8
- package/dist/containers/m3u/select-stream.d.ts +3 -2
- package/dist/containers/m3u/select-stream.js +9 -13
- package/dist/containers/m3u/types.d.ts +1 -1
- package/dist/containers/m3u/types.js +1 -2
- package/dist/containers/mp3/get-duration.js +5 -9
- package/dist/containers/mp3/get-frame-length.js +2 -7
- package/dist/containers/mp3/get-metadata-from-mp3.d.ts +2 -2
- package/dist/containers/mp3/get-metadata-from-mp3.js +1 -5
- package/dist/containers/mp3/id3-v1.js +1 -5
- package/dist/containers/mp3/id3.js +1 -5
- package/dist/containers/mp3/parse-mp3.js +7 -11
- package/dist/containers/mp3/parse-mpeg-header.js +10 -14
- package/dist/containers/mp3/samples-per-mpeg-file.js +1 -5
- package/dist/containers/riff/expect-riff-box.js +11 -15
- package/dist/containers/riff/get-duration.js +7 -12
- package/dist/containers/riff/get-tracks-from-avi.js +20 -28
- package/dist/containers/riff/is-movi.js +1 -5
- package/dist/containers/riff/parse-avih.js +1 -5
- package/dist/containers/riff/parse-isft.js +1 -5
- package/dist/containers/riff/parse-list-box.js +3 -7
- package/dist/containers/riff/parse-movi.js +13 -18
- package/dist/containers/riff/parse-riff-body.js +9 -13
- package/dist/containers/riff/parse-riff-box.js +9 -13
- package/dist/containers/riff/parse-riff-header.js +1 -5
- package/dist/containers/riff/parse-riff.js +5 -9
- package/dist/containers/riff/parse-strf.js +1 -5
- package/dist/containers/riff/parse-strh.js +3 -7
- package/dist/containers/riff/parse-video-section.js +7 -11
- package/dist/containers/riff/riff-box.js +1 -2
- package/dist/containers/riff/timescale.js +1 -4
- package/dist/containers/riff/traversal.js +7 -15
- package/dist/containers/transport-stream/adts-header.js +6 -10
- package/dist/containers/transport-stream/boxes.js +1 -2
- package/dist/containers/transport-stream/discard-rest-of-packet.js +2 -7
- package/dist/containers/transport-stream/find-separator.js +1 -4
- package/dist/containers/transport-stream/get-tracks.js +7 -12
- package/dist/containers/transport-stream/handle-aac-packet.js +12 -16
- package/dist/containers/transport-stream/handle-avc-packet.js +22 -26
- package/dist/containers/transport-stream/next-pes-header-store.js +1 -5
- package/dist/containers/transport-stream/parse-packet.js +13 -17
- package/dist/containers/transport-stream/parse-pat.js +5 -10
- package/dist/containers/transport-stream/parse-pes.js +1 -5
- package/dist/containers/transport-stream/parse-pmt.js +3 -7
- package/dist/containers/transport-stream/parse-stream-packet.js +13 -17
- package/dist/containers/transport-stream/parse-transport-stream.js +5 -9
- package/dist/containers/transport-stream/process-stream-buffers.js +10 -15
- package/dist/containers/transport-stream/traversal.js +4 -10
- package/dist/containers/wav/get-duration-from-wav.js +3 -8
- package/dist/containers/wav/get-metadata-from-wav.d.ts +2 -2
- package/dist/containers/wav/get-metadata-from-wav.js +1 -5
- package/dist/containers/wav/parse-data.js +5 -9
- package/dist/containers/wav/parse-fmt.js +3 -7
- package/dist/containers/wav/parse-header.js +1 -5
- package/dist/containers/wav/parse-id3.js +1 -5
- package/dist/containers/wav/parse-list.js +1 -5
- package/dist/containers/wav/parse-video-section.js +3 -7
- package/dist/containers/wav/parse-wav.js +15 -19
- package/dist/containers/wav/types.d.ts +2 -2
- package/dist/containers/wav/types.js +1 -2
- package/dist/containers/webm/allowed-partial-segments.js +1 -4
- package/dist/containers/webm/av1-codec-private.js +3 -7
- package/dist/containers/webm/color.js +6 -10
- package/dist/containers/webm/description.js +6 -10
- package/dist/containers/webm/get-ready-tracks.js +13 -18
- package/dist/containers/webm/get-sample-from-block.js +12 -16
- package/dist/containers/webm/make-track.js +43 -48
- package/dist/containers/webm/parse-ebml.js +14 -19
- package/dist/containers/webm/parse-webm-header.js +3 -7
- package/dist/containers/webm/segments/all-segments.js +168 -173
- package/dist/containers/webm/segments/block-simple-block-flags.js +4 -8
- package/dist/containers/webm/segments/track-entry.js +1 -5
- package/dist/containers/webm/segments.js +9 -13
- package/dist/containers/webm/traversal.js +37 -67
- package/dist/convert-audio-or-video-sample.js +1 -5
- package/dist/download-and-parse-media.js +44 -47
- package/dist/emit-available-info.js +38 -38
- package/dist/emitter.js +1 -5
- package/dist/errors.d.ts +2 -17
- package/dist/errors.js +10 -30
- package/dist/esm/fetch.mjs +93 -67
- package/dist/esm/index.mjs +679 -175
- package/dist/esm/node.mjs +59 -36
- package/dist/esm/universal.mjs +323 -0
- package/dist/esm/web-file.mjs +55 -43
- package/dist/esm/web.mjs +257 -0
- package/dist/esm/worker-server-entry.mjs +13056 -0
- package/dist/esm/worker-server.mjs +12914 -0
- package/dist/esm/worker-web-entry.mjs +12969 -0
- package/dist/esm/worker.mjs +439 -0
- package/dist/fetch.js +1 -17
- package/dist/file-types/bmp.js +3 -7
- package/dist/file-types/detect-file-type.js +24 -38
- package/dist/file-types/index.js +22 -26
- package/dist/file-types/jpeg.js +4 -9
- package/dist/file-types/pdf.js +3 -7
- package/dist/file-types/png.js +4 -9
- package/dist/file-types/webp.js +3 -7
- package/dist/forward-controller.js +1 -5
- package/dist/get-audio-codec.js +25 -38
- package/dist/get-container.d.ts +3 -3
- package/dist/get-container.js +5 -10
- package/dist/get-dimensions.js +8 -13
- package/dist/get-duration.js +27 -34
- package/dist/get-fields-from-callbacks.js +1 -5
- package/dist/get-fps.js +24 -34
- package/dist/get-is-hdr.js +5 -10
- package/dist/get-keyframes.js +6 -11
- package/dist/get-location.js +4 -9
- package/dist/get-number-of-audio-channels.js +2 -7
- package/dist/get-sample-aspect-ratio.js +17 -30
- package/dist/get-sample-positions-from-lpcm.js +5 -9
- package/dist/get-sample-positions.js +1 -5
- package/dist/get-sample-rate.js +2 -7
- package/dist/get-tracks.d.ts +5 -0
- package/dist/get-tracks.js +37 -44
- package/dist/get-video-codec.js +26 -34
- package/dist/has-all-info.js +33 -38
- package/dist/index.d.ts +15 -11
- package/dist/index.js +34 -48
- package/dist/init-video.d.ts +1 -1
- package/dist/init-video.js +47 -20
- package/dist/internal-parse-media.js +36 -40
- package/dist/is-audio-structure.d.ts +2 -2
- package/dist/is-audio-structure.js +1 -5
- package/dist/log.js +8 -12
- package/dist/make-hvc1-codec-strings.js +1 -5
- package/dist/media-parser-controller.js +7 -11
- package/dist/metadata/get-metadata.d.ts +4 -4
- package/dist/metadata/get-metadata.js +17 -22
- package/dist/metadata/metadata-from-iso.d.ts +3 -3
- package/dist/metadata/metadata-from-iso.js +12 -17
- package/dist/metadata/metadata-from-matroska.d.ts +2 -2
- package/dist/metadata/metadata-from-matroska.js +3 -7
- package/dist/metadata/metadata-from-riff.d.ts +2 -2
- package/dist/metadata/metadata-from-riff.js +3 -7
- package/dist/node-writer.js +1 -17
- package/dist/node.js +1 -17
- package/dist/options.d.ts +30 -24
- package/dist/options.js +1 -2
- package/dist/parse-media-on-browser-worker.d.ts +2 -0
- package/dist/parse-media-on-browser-worker.js +4 -0
- package/dist/parse-media-on-server-worker.d.ts +2 -0
- package/dist/parse-media-on-server-worker.js +4 -0
- package/dist/parse-media-on-web-worker.d.ts +2 -0
- package/dist/parse-media-on-web-worker.js +4 -0
- package/dist/parse-media-on-worker-entry.d.ts +2 -0
- package/dist/parse-media-on-worker-entry.js +269 -0
- package/dist/parse-media-on-worker.d.ts +2 -0
- package/dist/parse-media-on-worker.js +4 -0
- package/dist/parse-media.js +10 -13
- package/dist/parse-result.d.ts +3 -3
- package/dist/parse-result.js +1 -2
- package/dist/pause-signal.js +1 -5
- package/dist/perform-seek.js +6 -10
- package/dist/readers/fetch/get-body-and-reader.js +1 -5
- package/dist/readers/fetch/resolve-url.d.ts +1 -1
- package/dist/readers/fetch/resolve-url.js +1 -5
- package/dist/readers/from-fetch.d.ts +4 -1
- package/dist/readers/from-fetch.js +109 -94
- package/dist/readers/from-node.d.ts +4 -1
- package/dist/readers/from-node.js +58 -41
- package/dist/readers/from-web-file.d.ts +4 -1
- package/dist/readers/from-web-file.js +55 -49
- package/dist/readers/reader.d.ts +5 -1
- package/dist/readers/reader.js +1 -2
- package/dist/readers/universal.d.ts +2 -0
- package/dist/readers/universal.js +35 -0
- package/dist/readers/web.d.ts +2 -0
- package/dist/readers/web.js +22 -0
- package/dist/register-track.js +9 -15
- package/dist/remotion-license-acknowledge.js +4 -8
- package/dist/run-parse-iteration.js +26 -25
- package/dist/samples-from-moof.js +8 -12
- package/dist/skip.js +1 -5
- package/dist/state/aac-state.js +1 -5
- package/dist/state/can-skip-tracks.d.ts +2 -2
- package/dist/state/can-skip-tracks.js +3 -8
- package/dist/state/emitted-fields.js +1 -5
- package/dist/state/flac-state.js +1 -5
- package/dist/state/has-tracks-section.js +3 -7
- package/dist/state/images.js +1 -5
- package/dist/state/iso-base-media/cached-sample-positions.js +8 -13
- package/dist/state/iso-base-media/iso-state.js +5 -9
- package/dist/state/iso-base-media/moov-box.js +1 -5
- package/dist/state/keyframes.js +1 -5
- package/dist/state/last-eventloop-break.js +3 -7
- package/dist/state/m3u-state.d.ts +3 -0
- package/dist/state/m3u-state.js +16 -11
- package/dist/state/may-skip-video-data.js +3 -7
- package/dist/state/mp3.js +1 -5
- package/dist/state/need-samples-for-fields.js +1 -5
- package/dist/state/parser-state.d.ts +12 -10
- package/dist/state/parser-state.js +36 -41
- package/dist/state/riff.js +1 -5
- package/dist/state/sample-callbacks.js +8 -12
- package/dist/state/slow-duration-fps.js +1 -5
- package/dist/state/structure.d.ts +4 -4
- package/dist/state/structure.js +1 -5
- package/dist/state/transport-stream.js +3 -7
- package/dist/state/video-section.js +1 -5
- package/dist/state/webm.js +5 -9
- package/dist/throttled-progress.js +1 -5
- package/dist/truthy.js +1 -4
- package/dist/universal.d.ts +1 -0
- package/dist/universal.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -4
- package/dist/web-file.js +1 -17
- package/dist/web.d.ts +1 -0
- package/dist/web.js +1 -0
- package/dist/webcodec-sample-types.d.ts +6 -4
- package/dist/webcodec-sample-types.js +1 -2
- package/dist/worker/forward-controller.d.ts +3 -0
- package/dist/worker/forward-controller.js +20 -0
- package/dist/worker/serialize-error.d.ts +4 -0
- package/dist/worker/serialize-error.js +95 -0
- package/dist/worker/worker-types.d.ts +243 -0
- package/dist/worker/worker-types.js +1 -0
- package/dist/worker-bun-entry.d.ts +1 -0
- package/dist/worker-bun-entry.js +5 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +5 -0
- package/dist/worker-server-entry.d.ts +1 -0
- package/dist/worker-server-entry.js +5 -0
- package/dist/worker-server.d.ts +2 -0
- package/dist/worker-server.js +381 -0
- package/dist/worker-web-entry.d.ts +1 -0
- package/dist/worker-web-entry.js +5 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +267 -0
- package/dist/writers/node.js +16 -23
- package/dist/writers/writer.js +1 -2
- package/package.json +40 -21
- package/fetch.js +0 -2
- package/test.json +0 -663
- package/web-file.js +0 -2
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
class IsAGifError extends Error {
|
|
3
|
+
mimeType;
|
|
4
|
+
sizeInBytes;
|
|
5
|
+
fileName;
|
|
6
|
+
constructor({
|
|
7
|
+
message,
|
|
8
|
+
mimeType,
|
|
9
|
+
sizeInBytes,
|
|
10
|
+
fileName
|
|
11
|
+
}) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "IsAGifError";
|
|
14
|
+
this.fileName = "IsAGifError";
|
|
15
|
+
this.mimeType = mimeType;
|
|
16
|
+
this.sizeInBytes = sizeInBytes;
|
|
17
|
+
this.fileName = fileName;
|
|
18
|
+
if (Error.captureStackTrace) {
|
|
19
|
+
Error.captureStackTrace(this, IsAGifError);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class IsAnImageError extends Error {
|
|
25
|
+
imageType;
|
|
26
|
+
dimensions;
|
|
27
|
+
mimeType;
|
|
28
|
+
sizeInBytes;
|
|
29
|
+
fileName;
|
|
30
|
+
constructor({
|
|
31
|
+
dimensions,
|
|
32
|
+
imageType,
|
|
33
|
+
message,
|
|
34
|
+
mimeType,
|
|
35
|
+
sizeInBytes,
|
|
36
|
+
fileName
|
|
37
|
+
}) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = "IsAnImageError";
|
|
40
|
+
this.imageType = imageType;
|
|
41
|
+
this.dimensions = dimensions;
|
|
42
|
+
this.mimeType = mimeType;
|
|
43
|
+
this.sizeInBytes = sizeInBytes;
|
|
44
|
+
this.fileName = fileName;
|
|
45
|
+
if (Error.captureStackTrace) {
|
|
46
|
+
Error.captureStackTrace(this, IsAnImageError);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class IsAPdfError extends Error {
|
|
52
|
+
mimeType;
|
|
53
|
+
sizeInBytes;
|
|
54
|
+
fileName;
|
|
55
|
+
constructor({
|
|
56
|
+
message,
|
|
57
|
+
mimeType,
|
|
58
|
+
sizeInBytes,
|
|
59
|
+
fileName
|
|
60
|
+
}) {
|
|
61
|
+
super(message);
|
|
62
|
+
this.name = "IsAPdfError";
|
|
63
|
+
this.mimeType = mimeType;
|
|
64
|
+
this.sizeInBytes = sizeInBytes;
|
|
65
|
+
this.fileName = fileName;
|
|
66
|
+
if (Error.captureStackTrace) {
|
|
67
|
+
Error.captureStackTrace(this, IsAPdfError);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class IsAnUnsupportedFileTypeError extends Error {
|
|
73
|
+
mimeType;
|
|
74
|
+
sizeInBytes;
|
|
75
|
+
fileName;
|
|
76
|
+
constructor({
|
|
77
|
+
message,
|
|
78
|
+
mimeType,
|
|
79
|
+
sizeInBytes,
|
|
80
|
+
fileName
|
|
81
|
+
}) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.name = "IsAnUnsupportedFileTypeError";
|
|
84
|
+
this.mimeType = mimeType;
|
|
85
|
+
this.sizeInBytes = sizeInBytes;
|
|
86
|
+
this.fileName = fileName;
|
|
87
|
+
if (Error.captureStackTrace) {
|
|
88
|
+
Error.captureStackTrace(this, IsAnUnsupportedFileTypeError);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
class MediaParserAbortError extends Error {
|
|
94
|
+
constructor(message) {
|
|
95
|
+
super(message);
|
|
96
|
+
this.name = "MediaParserAbortError";
|
|
97
|
+
this.cause = undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/worker/serialize-error.ts
|
|
102
|
+
var deserializeError = (error) => {
|
|
103
|
+
switch (error.errorName) {
|
|
104
|
+
case "IsAGifError":
|
|
105
|
+
return new IsAGifError({
|
|
106
|
+
fileName: error.fileName,
|
|
107
|
+
mimeType: error.mimeType,
|
|
108
|
+
sizeInBytes: error.sizeInBytes,
|
|
109
|
+
message: error.errorMessage
|
|
110
|
+
});
|
|
111
|
+
case "IsAnImageError":
|
|
112
|
+
return new IsAnImageError({
|
|
113
|
+
dimensions: error.dimensions,
|
|
114
|
+
fileName: error.fileName,
|
|
115
|
+
imageType: error.imageType,
|
|
116
|
+
mimeType: error.mimeType,
|
|
117
|
+
sizeInBytes: error.sizeInBytes,
|
|
118
|
+
message: error.errorMessage
|
|
119
|
+
});
|
|
120
|
+
case "IsAPdfError":
|
|
121
|
+
return new IsAPdfError({
|
|
122
|
+
fileName: error.fileName,
|
|
123
|
+
mimeType: error.mimeType,
|
|
124
|
+
sizeInBytes: error.sizeInBytes,
|
|
125
|
+
message: error.errorMessage
|
|
126
|
+
});
|
|
127
|
+
case "IsAnUnsupportedFileTypeError":
|
|
128
|
+
return new IsAnUnsupportedFileTypeError({
|
|
129
|
+
fileName: error.fileName,
|
|
130
|
+
mimeType: error.mimeType,
|
|
131
|
+
sizeInBytes: error.sizeInBytes,
|
|
132
|
+
message: error.errorMessage
|
|
133
|
+
});
|
|
134
|
+
case "MediaParserAbortError":
|
|
135
|
+
return new MediaParserAbortError(error.errorMessage);
|
|
136
|
+
default:
|
|
137
|
+
return new Error(error.errorMessage);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// src/worker.ts
|
|
142
|
+
var convertToWorkerPayload = (payload) => {
|
|
143
|
+
const {
|
|
144
|
+
onAudioCodec,
|
|
145
|
+
onContainer,
|
|
146
|
+
onDimensions,
|
|
147
|
+
onUnrotatedDimensions,
|
|
148
|
+
onVideoCodec,
|
|
149
|
+
onFps,
|
|
150
|
+
onAudioTrack,
|
|
151
|
+
onDurationInSeconds,
|
|
152
|
+
onImages,
|
|
153
|
+
onInternalStats,
|
|
154
|
+
onIsHdr,
|
|
155
|
+
onKeyframes,
|
|
156
|
+
onLocation,
|
|
157
|
+
onM3uStreams,
|
|
158
|
+
onMetadata,
|
|
159
|
+
onMimeType,
|
|
160
|
+
onName,
|
|
161
|
+
onNumberOfAudioChannels,
|
|
162
|
+
onParseProgress,
|
|
163
|
+
onRotation,
|
|
164
|
+
onSampleRate,
|
|
165
|
+
onSlowAudioBitrate,
|
|
166
|
+
onSize,
|
|
167
|
+
onSlowDurationInSeconds,
|
|
168
|
+
onSlowFps,
|
|
169
|
+
onSlowKeyframes,
|
|
170
|
+
onSlowNumberOfFrames,
|
|
171
|
+
onSlowVideoBitrate,
|
|
172
|
+
onStructure,
|
|
173
|
+
onTracks,
|
|
174
|
+
onVideoTrack,
|
|
175
|
+
selectM3uStream,
|
|
176
|
+
selectM3uAssociatedPlaylists,
|
|
177
|
+
...others
|
|
178
|
+
} = payload;
|
|
179
|
+
return {
|
|
180
|
+
type: "request-worker",
|
|
181
|
+
payload: others,
|
|
182
|
+
postAudioCodec: Boolean(onAudioCodec),
|
|
183
|
+
postContainer: Boolean(onContainer),
|
|
184
|
+
postDimensions: Boolean(onDimensions),
|
|
185
|
+
postDurationInSeconds: Boolean(onDurationInSeconds),
|
|
186
|
+
postFps: Boolean(onFps),
|
|
187
|
+
postImages: Boolean(onImages),
|
|
188
|
+
postInternalStats: Boolean(onInternalStats),
|
|
189
|
+
postIsHdr: Boolean(onIsHdr),
|
|
190
|
+
postKeyframes: Boolean(onKeyframes),
|
|
191
|
+
postLocation: Boolean(onLocation),
|
|
192
|
+
postM3uStreams: Boolean(onM3uStreams),
|
|
193
|
+
postMetadata: Boolean(onMetadata),
|
|
194
|
+
postMimeType: Boolean(onMimeType),
|
|
195
|
+
postName: Boolean(onName),
|
|
196
|
+
postNumberOfAudioChannels: Boolean(onNumberOfAudioChannels),
|
|
197
|
+
postRotation: Boolean(onRotation),
|
|
198
|
+
postSampleRate: Boolean(onSampleRate),
|
|
199
|
+
postSlowAudioBitrate: Boolean(onSlowAudioBitrate),
|
|
200
|
+
postSlowDurationInSeconds: Boolean(onSlowDurationInSeconds),
|
|
201
|
+
postSlowFps: Boolean(onSlowFps),
|
|
202
|
+
postSlowKeyframes: Boolean(onSlowKeyframes),
|
|
203
|
+
postSlowNumberOfFrames: Boolean(onSlowNumberOfFrames),
|
|
204
|
+
postSlowVideoBitrate: Boolean(onSlowVideoBitrate),
|
|
205
|
+
postStructure: Boolean(onStructure),
|
|
206
|
+
postTracks: Boolean(onTracks),
|
|
207
|
+
postUnrotatedDimensions: Boolean(onUnrotatedDimensions),
|
|
208
|
+
postVideoCodec: Boolean(onVideoCodec),
|
|
209
|
+
postSize: Boolean(onSize),
|
|
210
|
+
postParseProgress: Boolean(onParseProgress),
|
|
211
|
+
postM3uStreamSelection: Boolean(selectM3uStream),
|
|
212
|
+
postM3uAssociatedPlaylistsSelection: Boolean(selectM3uAssociatedPlaylists),
|
|
213
|
+
postOnAudioTrack: Boolean(onAudioTrack),
|
|
214
|
+
postOnVideoTrack: Boolean(onVideoTrack)
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
var post = (worker, payload) => {
|
|
218
|
+
worker.postMessage(payload);
|
|
219
|
+
};
|
|
220
|
+
var parseMediaOnWorker = async ({
|
|
221
|
+
controller,
|
|
222
|
+
...params
|
|
223
|
+
}) => {
|
|
224
|
+
if (typeof Worker === "undefined") {
|
|
225
|
+
throw new Error('"Worker" is not available. Cannot call workerClient()');
|
|
226
|
+
}
|
|
227
|
+
const worker = new Worker(new URL("./worker-server", import.meta.url));
|
|
228
|
+
post(worker, convertToWorkerPayload(params));
|
|
229
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
230
|
+
const onAbort = () => {
|
|
231
|
+
post(worker, { type: "request-abort" });
|
|
232
|
+
};
|
|
233
|
+
const onResume = () => {
|
|
234
|
+
post(worker, { type: "request-resume" });
|
|
235
|
+
};
|
|
236
|
+
const onPause = () => {
|
|
237
|
+
post(worker, { type: "request-pause" });
|
|
238
|
+
};
|
|
239
|
+
const callbacks = {};
|
|
240
|
+
function onMessage(message) {
|
|
241
|
+
const data = message.data;
|
|
242
|
+
if (data.type === "response-done") {
|
|
243
|
+
resolve(data.payload);
|
|
244
|
+
}
|
|
245
|
+
if (data.type === "response-error") {
|
|
246
|
+
cleanup();
|
|
247
|
+
reject(deserializeError(data));
|
|
248
|
+
}
|
|
249
|
+
if (data.type === "response-on-callback-request") {
|
|
250
|
+
Promise.resolve().then(async () => {
|
|
251
|
+
if (data.payload.callbackType === "audio-codec") {
|
|
252
|
+
await params.onAudioCodec?.(data.payload.value);
|
|
253
|
+
return { payloadType: "void" };
|
|
254
|
+
}
|
|
255
|
+
if (data.payload.callbackType === "container") {
|
|
256
|
+
await params.onContainer?.(data.payload.value);
|
|
257
|
+
return { payloadType: "void" };
|
|
258
|
+
}
|
|
259
|
+
if (data.payload.callbackType === "dimensions") {
|
|
260
|
+
await params.onDimensions?.(data.payload.value);
|
|
261
|
+
return { payloadType: "void" };
|
|
262
|
+
}
|
|
263
|
+
if (data.payload.callbackType === "unrotated-dimensions") {
|
|
264
|
+
await params.onUnrotatedDimensions?.(data.payload.value);
|
|
265
|
+
return { payloadType: "void" };
|
|
266
|
+
}
|
|
267
|
+
if (data.payload.callbackType === "video-codec") {
|
|
268
|
+
await params.onVideoCodec?.(data.payload.value);
|
|
269
|
+
return { payloadType: "void" };
|
|
270
|
+
}
|
|
271
|
+
if (data.payload.callbackType === "tracks") {
|
|
272
|
+
await params.onTracks?.(data.payload.value);
|
|
273
|
+
return { payloadType: "void" };
|
|
274
|
+
}
|
|
275
|
+
if (data.payload.callbackType === "rotation") {
|
|
276
|
+
await params.onRotation?.(data.payload.value);
|
|
277
|
+
return { payloadType: "void" };
|
|
278
|
+
}
|
|
279
|
+
if (data.payload.callbackType === "sample-rate") {
|
|
280
|
+
await params.onSampleRate?.(data.payload.value);
|
|
281
|
+
return { payloadType: "void" };
|
|
282
|
+
}
|
|
283
|
+
if (data.payload.callbackType === "slow-audio-bitrate") {
|
|
284
|
+
await params.onSlowAudioBitrate?.(data.payload.value);
|
|
285
|
+
return { payloadType: "void" };
|
|
286
|
+
}
|
|
287
|
+
if (data.payload.callbackType === "slow-duration-in-seconds") {
|
|
288
|
+
await params.onSlowDurationInSeconds?.(data.payload.value);
|
|
289
|
+
return { payloadType: "void" };
|
|
290
|
+
}
|
|
291
|
+
if (data.payload.callbackType === "slow-fps") {
|
|
292
|
+
await params.onSlowFps?.(data.payload.value);
|
|
293
|
+
return { payloadType: "void" };
|
|
294
|
+
}
|
|
295
|
+
if (data.payload.callbackType === "slow-keyframes") {
|
|
296
|
+
await params.onSlowKeyframes?.(data.payload.value);
|
|
297
|
+
return { payloadType: "void" };
|
|
298
|
+
}
|
|
299
|
+
if (data.payload.callbackType === "slow-number-of-frames") {
|
|
300
|
+
await params.onSlowNumberOfFrames?.(data.payload.value);
|
|
301
|
+
return { payloadType: "void" };
|
|
302
|
+
}
|
|
303
|
+
if (data.payload.callbackType === "slow-video-bitrate") {
|
|
304
|
+
await params.onSlowVideoBitrate?.(data.payload.value);
|
|
305
|
+
return { payloadType: "void" };
|
|
306
|
+
}
|
|
307
|
+
if (data.payload.callbackType === "structure") {
|
|
308
|
+
await params.onStructure?.(data.payload.value);
|
|
309
|
+
return { payloadType: "void" };
|
|
310
|
+
}
|
|
311
|
+
if (data.payload.callbackType === "fps") {
|
|
312
|
+
await params.onFps?.(data.payload.value);
|
|
313
|
+
return { payloadType: "void" };
|
|
314
|
+
}
|
|
315
|
+
if (data.payload.callbackType === "images") {
|
|
316
|
+
await params.onImages?.(data.payload.value);
|
|
317
|
+
return { payloadType: "void" };
|
|
318
|
+
}
|
|
319
|
+
if (data.payload.callbackType === "internal-stats") {
|
|
320
|
+
await params.onInternalStats?.(data.payload.value);
|
|
321
|
+
return { payloadType: "void" };
|
|
322
|
+
}
|
|
323
|
+
if (data.payload.callbackType === "is-hdr") {
|
|
324
|
+
await params.onIsHdr?.(data.payload.value);
|
|
325
|
+
return { payloadType: "void" };
|
|
326
|
+
}
|
|
327
|
+
if (data.payload.callbackType === "keyframes") {
|
|
328
|
+
await params.onKeyframes?.(data.payload.value);
|
|
329
|
+
return { payloadType: "void" };
|
|
330
|
+
}
|
|
331
|
+
if (data.payload.callbackType === "location") {
|
|
332
|
+
await params.onLocation?.(data.payload.value);
|
|
333
|
+
return { payloadType: "void" };
|
|
334
|
+
}
|
|
335
|
+
if (data.payload.callbackType === "m3u-streams") {
|
|
336
|
+
await params.onM3uStreams?.(data.payload.value);
|
|
337
|
+
return { payloadType: "void" };
|
|
338
|
+
}
|
|
339
|
+
if (data.payload.callbackType === "metadata") {
|
|
340
|
+
await params.onMetadata?.(data.payload.value);
|
|
341
|
+
return { payloadType: "void" };
|
|
342
|
+
}
|
|
343
|
+
if (data.payload.callbackType === "mime-type") {
|
|
344
|
+
await params.onMimeType?.(data.payload.value);
|
|
345
|
+
return { payloadType: "void" };
|
|
346
|
+
}
|
|
347
|
+
if (data.payload.callbackType === "name") {
|
|
348
|
+
await params.onName?.(data.payload.value);
|
|
349
|
+
return { payloadType: "void" };
|
|
350
|
+
}
|
|
351
|
+
if (data.payload.callbackType === "number-of-audio-channels") {
|
|
352
|
+
await params.onNumberOfAudioChannels?.(data.payload.value);
|
|
353
|
+
return { payloadType: "void" };
|
|
354
|
+
}
|
|
355
|
+
if (data.payload.callbackType === "size") {
|
|
356
|
+
await params.onSize?.(data.payload.value);
|
|
357
|
+
return { payloadType: "void" };
|
|
358
|
+
}
|
|
359
|
+
if (data.payload.callbackType === "duration-in-seconds") {
|
|
360
|
+
await params.onDurationInSeconds?.(data.payload.value);
|
|
361
|
+
return { payloadType: "void" };
|
|
362
|
+
}
|
|
363
|
+
if (data.payload.callbackType === "parse-progress") {
|
|
364
|
+
await params.onParseProgress?.(data.payload.value);
|
|
365
|
+
return { payloadType: "void" };
|
|
366
|
+
}
|
|
367
|
+
if (data.payload.callbackType === "m3u-stream-selection") {
|
|
368
|
+
const selection = await params.selectM3uStream(data.payload.value);
|
|
369
|
+
return { payloadType: "m3u-stream-selection", value: selection };
|
|
370
|
+
}
|
|
371
|
+
if (data.payload.callbackType === "m3u-associated-playlists-selection") {
|
|
372
|
+
const selection = await params.selectM3uAssociatedPlaylists(data.payload.value);
|
|
373
|
+
return {
|
|
374
|
+
payloadType: "m3u-associated-playlists-selection",
|
|
375
|
+
value: selection
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
if (data.payload.callbackType === "on-audio-track") {
|
|
379
|
+
const possibleCallback = await params.onAudioTrack?.(data.payload.value);
|
|
380
|
+
if (possibleCallback) {
|
|
381
|
+
callbacks[data.payload.value.track.trackId] = possibleCallback;
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
payloadType: "on-audio-track-response",
|
|
385
|
+
registeredCallback: Boolean(possibleCallback)
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (data.payload.callbackType === "on-video-track") {
|
|
389
|
+
const possibleCallback = await params.onVideoTrack?.(data.payload.value);
|
|
390
|
+
if (possibleCallback) {
|
|
391
|
+
callbacks[data.payload.value.track.trackId] = possibleCallback;
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
payloadType: "on-video-track-response",
|
|
395
|
+
registeredCallback: Boolean(possibleCallback)
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
if (data.payload.callbackType === "on-audio-video-sample") {
|
|
399
|
+
const callback = callbacks[data.payload.trackId];
|
|
400
|
+
if (!callback) {
|
|
401
|
+
throw new Error(`No callback registered for track ${data.payload.trackId}`);
|
|
402
|
+
}
|
|
403
|
+
await callback(data.payload.value);
|
|
404
|
+
return { payloadType: "void" };
|
|
405
|
+
}
|
|
406
|
+
throw new Error(`Unknown callback type: ${data.payload}`);
|
|
407
|
+
}).then((payload) => {
|
|
408
|
+
post(worker, {
|
|
409
|
+
type: "acknowledge-callback",
|
|
410
|
+
nonce: data.nonce,
|
|
411
|
+
...payload
|
|
412
|
+
});
|
|
413
|
+
}).catch((err) => {
|
|
414
|
+
reject(err);
|
|
415
|
+
post(worker, {
|
|
416
|
+
type: "signal-error-in-callback",
|
|
417
|
+
nonce: data.nonce
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
worker.addEventListener("message", onMessage);
|
|
423
|
+
controller?.addEventListener("abort", onAbort);
|
|
424
|
+
controller?.addEventListener("resume", onResume);
|
|
425
|
+
controller?.addEventListener("pause", onPause);
|
|
426
|
+
function cleanup() {
|
|
427
|
+
worker.removeEventListener("message", onMessage);
|
|
428
|
+
controller?.removeEventListener("abort", onAbort);
|
|
429
|
+
controller?.removeEventListener("resume", onResume);
|
|
430
|
+
controller?.removeEventListener("pause", onPause);
|
|
431
|
+
worker.terminate();
|
|
432
|
+
}
|
|
433
|
+
const val = await promise;
|
|
434
|
+
cleanup();
|
|
435
|
+
return val;
|
|
436
|
+
};
|
|
437
|
+
export {
|
|
438
|
+
parseMediaOnWorker
|
|
439
|
+
};
|
package/dist/fetch.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./readers/from-fetch"), exports);
|
|
1
|
+
export * from './readers/from-fetch';
|
package/dist/file-types/bmp.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBmp = void 0;
|
|
4
|
-
const detect_file_type_1 = require("./detect-file-type");
|
|
1
|
+
import { matchesPattern } from './detect-file-type';
|
|
5
2
|
function getBmpDimensions(bmpData) {
|
|
6
3
|
if (bmpData.length < 26) {
|
|
7
4
|
return null;
|
|
@@ -12,12 +9,11 @@ function getBmpDimensions(bmpData) {
|
|
|
12
9
|
height: Math.abs(view.getInt32(22, true)),
|
|
13
10
|
};
|
|
14
11
|
}
|
|
15
|
-
const isBmp = (data) => {
|
|
12
|
+
export const isBmp = (data) => {
|
|
16
13
|
const bmpPattern = new Uint8Array([0x42, 0x4d]);
|
|
17
|
-
if (
|
|
14
|
+
if (matchesPattern(bmpPattern)(data.subarray(0, 2))) {
|
|
18
15
|
const bmp = getBmpDimensions(data);
|
|
19
16
|
return { dimensions: bmp, type: 'bmp' };
|
|
20
17
|
}
|
|
21
18
|
return null;
|
|
22
19
|
};
|
|
23
|
-
exports.isBmp = isBmp;
|
|
@@ -1,74 +1,60 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isM3u = exports.isFlac = exports.isAac = exports.isGif = exports.isMp3 = exports.isTransportStream = exports.isIsoBaseMedia = exports.isWebm = exports.isRiffWave = exports.isRiffAvi = exports.matchesPattern = void 0;
|
|
4
1
|
const webmPattern = new Uint8Array([0x1a, 0x45, 0xdf, 0xa3]);
|
|
5
|
-
const matchesPattern = (pattern) => {
|
|
2
|
+
export const matchesPattern = (pattern) => {
|
|
6
3
|
return (data) => {
|
|
7
4
|
return pattern.every((value, index) => data[index] === value);
|
|
8
5
|
};
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
const isRiffAvi = (data) => {
|
|
7
|
+
export const isRiffAvi = (data) => {
|
|
12
8
|
const riffPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
13
|
-
if (!
|
|
9
|
+
if (!matchesPattern(riffPattern)(data.subarray(0, 4))) {
|
|
14
10
|
return false;
|
|
15
11
|
}
|
|
16
12
|
const fileType = data.subarray(8, 12);
|
|
17
13
|
const aviPattern = new Uint8Array([0x41, 0x56, 0x49, 0x20]);
|
|
18
|
-
return
|
|
14
|
+
return matchesPattern(aviPattern)(fileType);
|
|
19
15
|
};
|
|
20
|
-
|
|
21
|
-
const isRiffWave = (data) => {
|
|
16
|
+
export const isRiffWave = (data) => {
|
|
22
17
|
const riffPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
23
|
-
if (!
|
|
18
|
+
if (!matchesPattern(riffPattern)(data.subarray(0, 4))) {
|
|
24
19
|
return false;
|
|
25
20
|
}
|
|
26
21
|
const fileType = data.subarray(8, 12);
|
|
27
22
|
const wavePattern = new Uint8Array([0x57, 0x41, 0x56, 0x45]);
|
|
28
|
-
return
|
|
23
|
+
return matchesPattern(wavePattern)(fileType);
|
|
29
24
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return (0, exports.matchesPattern)(webmPattern)(data.subarray(0, 4));
|
|
25
|
+
export const isWebm = (data) => {
|
|
26
|
+
return matchesPattern(webmPattern)(data.subarray(0, 4));
|
|
33
27
|
};
|
|
34
|
-
|
|
35
|
-
const isIsoBaseMedia = (data) => {
|
|
28
|
+
export const isIsoBaseMedia = (data) => {
|
|
36
29
|
const isoBaseMediaMp4Pattern = new TextEncoder().encode('ftyp');
|
|
37
|
-
return
|
|
30
|
+
return matchesPattern(isoBaseMediaMp4Pattern)(data.subarray(4, 8));
|
|
38
31
|
};
|
|
39
|
-
|
|
40
|
-
const isTransportStream = (data) => {
|
|
32
|
+
export const isTransportStream = (data) => {
|
|
41
33
|
return data[0] === 0x47 && data[188] === 0x47;
|
|
42
34
|
};
|
|
43
|
-
|
|
44
|
-
const isMp3 = (data) => {
|
|
35
|
+
export const isMp3 = (data) => {
|
|
45
36
|
const mpegPattern = new Uint8Array([0xff, 0xf3, 0xe4, 0x64]);
|
|
46
37
|
const id3v4Pattern = new Uint8Array([0x49, 0x44, 0x33, 4]);
|
|
47
38
|
const id3v3Pattern = new Uint8Array([0x49, 0x44, 0x33, 3]);
|
|
48
39
|
const id3v2Pattern = new Uint8Array([0x49, 0x44, 0x33, 2]);
|
|
49
40
|
const subarray = data.subarray(0, 4);
|
|
50
|
-
return (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
return (matchesPattern(mpegPattern)(subarray) ||
|
|
42
|
+
matchesPattern(id3v4Pattern)(subarray) ||
|
|
43
|
+
matchesPattern(id3v3Pattern)(subarray) ||
|
|
44
|
+
matchesPattern(id3v2Pattern)(subarray));
|
|
54
45
|
};
|
|
55
|
-
|
|
56
|
-
const isGif = (data) => {
|
|
46
|
+
export const isGif = (data) => {
|
|
57
47
|
const gifPattern = new Uint8Array([0x47, 0x49, 0x46, 0x38]);
|
|
58
|
-
return
|
|
48
|
+
return matchesPattern(gifPattern)(data.subarray(0, 4));
|
|
59
49
|
};
|
|
60
|
-
|
|
61
|
-
const isAac = (data) => {
|
|
50
|
+
export const isAac = (data) => {
|
|
62
51
|
const aacPattern = new Uint8Array([0xff, 0xf1]);
|
|
63
|
-
return
|
|
52
|
+
return matchesPattern(aacPattern)(data.subarray(0, 2));
|
|
64
53
|
};
|
|
65
|
-
|
|
66
|
-
const isFlac = (data) => {
|
|
54
|
+
export const isFlac = (data) => {
|
|
67
55
|
const flacPattern = new Uint8Array([0x66, 0x4c, 0x61, 0x43]);
|
|
68
|
-
return
|
|
56
|
+
return matchesPattern(flacPattern)(data.subarray(0, 4));
|
|
69
57
|
};
|
|
70
|
-
|
|
71
|
-
const isM3u = (data) => {
|
|
58
|
+
export const isM3u = (data) => {
|
|
72
59
|
return new TextDecoder('utf-8').decode(data.slice(0, 7)) === '#EXTM3U';
|
|
73
60
|
};
|
|
74
|
-
exports.isM3u = isM3u;
|
package/dist/file-types/index.js
CHANGED
|
@@ -1,63 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const webp_1 = require("./webp");
|
|
10
|
-
const detectFileType = (data) => {
|
|
11
|
-
if ((0, detect_file_type_1.isRiffWave)(data)) {
|
|
1
|
+
import { isBmp } from './bmp';
|
|
2
|
+
import { isAac, isFlac, isGif, isIsoBaseMedia, isM3u, isMp3, isRiffAvi, isRiffWave, isTransportStream, isWebm, } from './detect-file-type';
|
|
3
|
+
import { isJpeg } from './jpeg';
|
|
4
|
+
import { isPdf } from './pdf';
|
|
5
|
+
import { isPng } from './png';
|
|
6
|
+
import { isWebp } from './webp';
|
|
7
|
+
export const detectFileType = (data) => {
|
|
8
|
+
if (isRiffWave(data)) {
|
|
12
9
|
return { type: 'wav' };
|
|
13
10
|
}
|
|
14
|
-
if (
|
|
11
|
+
if (isRiffAvi(data)) {
|
|
15
12
|
return { type: 'riff' };
|
|
16
13
|
}
|
|
17
|
-
if (
|
|
14
|
+
if (isAac(data)) {
|
|
18
15
|
return { type: 'aac' };
|
|
19
16
|
}
|
|
20
|
-
if (
|
|
17
|
+
if (isFlac(data)) {
|
|
21
18
|
return { type: 'flac' };
|
|
22
19
|
}
|
|
23
|
-
if (
|
|
20
|
+
if (isM3u(data)) {
|
|
24
21
|
return { type: 'm3u' };
|
|
25
22
|
}
|
|
26
|
-
const webp =
|
|
23
|
+
const webp = isWebp(data);
|
|
27
24
|
if (webp) {
|
|
28
25
|
return webp;
|
|
29
26
|
}
|
|
30
|
-
if (
|
|
27
|
+
if (isWebm(data)) {
|
|
31
28
|
return { type: 'webm' };
|
|
32
29
|
}
|
|
33
|
-
if (
|
|
30
|
+
if (isIsoBaseMedia(data)) {
|
|
34
31
|
return { type: 'iso-base-media' };
|
|
35
32
|
}
|
|
36
|
-
if (
|
|
33
|
+
if (isTransportStream(data)) {
|
|
37
34
|
return { type: 'transport-stream' };
|
|
38
35
|
}
|
|
39
|
-
if (
|
|
36
|
+
if (isMp3(data)) {
|
|
40
37
|
return { type: 'mp3' };
|
|
41
38
|
}
|
|
42
|
-
if (
|
|
39
|
+
if (isGif(data)) {
|
|
43
40
|
return { type: 'gif' };
|
|
44
41
|
}
|
|
45
|
-
const png =
|
|
42
|
+
const png = isPng(data);
|
|
46
43
|
if (png) {
|
|
47
44
|
return png;
|
|
48
45
|
}
|
|
49
|
-
const pdf =
|
|
46
|
+
const pdf = isPdf(data);
|
|
50
47
|
if (pdf) {
|
|
51
48
|
return pdf;
|
|
52
49
|
}
|
|
53
|
-
const bmp =
|
|
50
|
+
const bmp = isBmp(data);
|
|
54
51
|
if (bmp) {
|
|
55
52
|
return bmp;
|
|
56
53
|
}
|
|
57
|
-
const jpeg =
|
|
54
|
+
const jpeg = isJpeg(data);
|
|
58
55
|
if (jpeg) {
|
|
59
56
|
return jpeg;
|
|
60
57
|
}
|
|
61
58
|
return { type: 'unknown' };
|
|
62
59
|
};
|
|
63
|
-
exports.detectFileType = detectFileType;
|