azot 5.0.0-alpha.80 → 5.0.0-alpha.86
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/api.mjs +1 -1
- package/dist/azot.mjs +2 -2
- package/dist/build-BFjRpmI0.mjs +1 -0
- package/dist/context-DZuEiTde.mjs +167 -0
- package/dist/context.mjs +1 -1
- package/dist/definition-9gPpvQnY.mjs +4 -0
- package/dist/dev-DynQt6bq.mjs +1 -0
- package/dist/dist-Dv5JJo-X.mjs +29 -0
- package/dist/errors-98yB_Pya.mjs +14 -0
- package/dist/guards-BNUlTH-l.mjs +1 -0
- package/dist/logger-Bq9rQNnb.mjs +22 -0
- package/dist/pack-mZaggfoF.mjs +1 -0
- package/dist/vitest.mjs +1 -1
- package/manifest_schema.json +193 -86
- package/node_modules/dasha/LICENSE +21 -0
- package/node_modules/dasha/README.md +188 -0
- package/node_modules/dasha/dist/index.d.mts +702 -0
- package/node_modules/dasha/dist/index.mjs +3108 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/CHANGELOG.md +1132 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/LICENSE +8 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/SECURITY.md +50 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/index.d.ts +1843 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/.eslintrc.yml +3 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/conventions.js +429 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/dom-parser.js +591 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/dom.js +3759 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/entities.js +2171 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/errors.js +205 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/grammar.js +559 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/index.js +41 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/lib/sax.js +983 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/package.json +77 -0
- package/node_modules/dasha/node_modules/@xmldom/xmldom/readme.md +366 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/LICENSE +21 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/README.md +307 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/apiHelpers.js +381 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/classApi-basic.js +1015 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/classApi-full.js +1016 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/classApi.js +119 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/exoticCalendars-utils.js +386 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/exoticCalendars.js +524 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/funcApi-native.d.ts +117 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/funcApi-native.js +1984 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/funcApi-shim.js +2099 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/funcApi.d.ts +154 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/funcApi.js +212 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/internal.d.ts +62 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/internal.js +3304 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/options.d.ts +2 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/options.js +280 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/chunks/root.js +3 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Calendar.d.ts +26 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Calendar.js +74 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Duration.d.ts +40 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Duration.js +45 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Instant.d.ts +93 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Instant.js +87 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Now.d.ts +14 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/Now.js +19 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainDate.d.ts +98 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainDate.js +117 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainDateTime.d.ts +178 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainDateTime.js +189 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainMonthDay.d.ts +23 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainMonthDay.js +33 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainTime.d.ts +104 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainTime.js +105 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainYearMonth.d.ts +55 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/PlainYearMonth.js +67 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/ZonedDateTime.d.ts +189 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/ZonedDateTime.js +199 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/index.d.ts +3 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/fns/index.js +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/global.d.ts +2 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/global.esm.js +3 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/global.js +4580 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/implementation.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/implementation.js +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/index.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/index.js +11 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/shim.d.ts +4 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/full/shim.js +21 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/global.d.ts +2 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/global.esm.js +3 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/global.js +3738 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/implementation.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/implementation.js +3 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/index.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/index.js +11 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-spec/LICENSE +19 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-spec/README.md +151 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-spec/global.d.ts +726 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-spec/global.js +0 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-spec/index.d.ts +733 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-spec/index.js +0 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-spec/package.json +45 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/LICENSE +21 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/README.md +866 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/diff.d.ts +17 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/diff.js +59 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/endOf.d.ts +9 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/endOf.js +56 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/errorMessages.d.ts +9 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/errorMessages.js +14 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/global-types.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/global-types.js +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/index.d.ts +6 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/index.js +5 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/protected-error-messages.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/protected-error-messages.js +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/protected.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/protected.js +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/round.d.ts +24 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/round.js +47 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/startOf.d.ts +9 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/startOf.js +73 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/utils.d.ts +20 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/utils.js +81 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/with.d.ts +3 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/dist/with.js +44 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/node_modules/temporal-utils/package.json +57 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/package.json +113 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/shim.d.ts +4 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/shim.js +21 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/types/global.d.ts +1 -0
- package/node_modules/dasha/node_modules/temporal-polyfill/types/global.js +1 -0
- package/node_modules/dasha/package.json +72 -0
- package/node_modules/mediabunny/LICENSE +373 -0
- package/node_modules/mediabunny/README.md +228 -0
- package/node_modules/mediabunny/dist/bundles/mediabunny.cjs +41799 -0
- package/node_modules/mediabunny/dist/bundles/mediabunny.min.cjs +51 -0
- package/node_modules/mediabunny/dist/bundles/mediabunny.min.mjs +50 -0
- package/node_modules/mediabunny/dist/bundles/mediabunny.mjs +41671 -0
- package/node_modules/mediabunny/dist/bundles/mediabunny.node.cjs +41801 -0
- package/node_modules/mediabunny/dist/mediabunny.d.ts +5596 -0
- package/node_modules/mediabunny/dist/modules/shared/aac-misc.d.ts +31 -0
- package/node_modules/mediabunny/dist/modules/shared/aac-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/shared/aac-misc.js +174 -0
- package/node_modules/mediabunny/dist/modules/shared/ac3-misc.d.ts +12 -0
- package/node_modules/mediabunny/dist/modules/shared/ac3-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/shared/ac3-misc.js +11 -0
- package/node_modules/mediabunny/dist/modules/shared/bitstream.d.ts +23 -0
- package/node_modules/mediabunny/dist/modules/shared/bitstream.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/shared/bitstream.js +78 -0
- package/node_modules/mediabunny/dist/modules/shared/dts-misc.d.ts +17 -0
- package/node_modules/mediabunny/dist/modules/shared/dts-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/shared/dts-misc.js +26 -0
- package/node_modules/mediabunny/dist/modules/shared/mp3-misc.d.ts +45 -0
- package/node_modules/mediabunny/dist/modules/shared/mp3-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/shared/mp3-misc.js +171 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-demuxer.d.ts +81 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-demuxer.js +287 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-muxer.d.ts +26 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-muxer.js +93 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-reader.d.ts +21 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-reader.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/adts/adts-reader.js +63 -0
- package/node_modules/mediabunny/dist/modules/src/aes.d.ts +27 -0
- package/node_modules/mediabunny/dist/modules/src/aes.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/aes.js +255 -0
- package/node_modules/mediabunny/dist/modules/src/codec-data.d.ts +414 -0
- package/node_modules/mediabunny/dist/modules/src/codec-data.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/codec-data.js +3101 -0
- package/node_modules/mediabunny/dist/modules/src/codec.d.ts +167 -0
- package/node_modules/mediabunny/dist/modules/src/codec.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/codec.js +1066 -0
- package/node_modules/mediabunny/dist/modules/src/conversion.d.ts +454 -0
- package/node_modules/mediabunny/dist/modules/src/conversion.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/conversion.js +1738 -0
- package/node_modules/mediabunny/dist/modules/src/custom-coder.d.ts +134 -0
- package/node_modules/mediabunny/dist/modules/src/custom-coder.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/custom-coder.js +124 -0
- package/node_modules/mediabunny/dist/modules/src/decode.d.ts +48 -0
- package/node_modules/mediabunny/dist/modules/src/decode.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/decode.js +195 -0
- package/node_modules/mediabunny/dist/modules/src/demuxer.d.ts +34 -0
- package/node_modules/mediabunny/dist/modules/src/demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/demuxer.js +15 -0
- package/node_modules/mediabunny/dist/modules/src/encode.d.ts +559 -0
- package/node_modules/mediabunny/dist/modules/src/encode.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/encode.js +812 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-demuxer.d.ts +107 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-demuxer.js +569 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-misc.d.ts +18 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-misc.js +136 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-muxer.d.ts +43 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/flac/flac-muxer.js +275 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-demuxer.d.ts +54 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-demuxer.js +714 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-misc.d.ts +42 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-misc.js +160 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-muxer.d.ts +123 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-muxer.js +1299 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-segmented-input.d.ts +58 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-segmented-input.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/hls/hls-segmented-input.js +662 -0
- package/node_modules/mediabunny/dist/modules/src/id3.d.ts +78 -0
- package/node_modules/mediabunny/dist/modules/src/id3.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/id3.js +910 -0
- package/node_modules/mediabunny/dist/modules/src/index.d.ts +33 -0
- package/node_modules/mediabunny/dist/modules/src/index.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/index.js +51 -0
- package/node_modules/mediabunny/dist/modules/src/input-format.d.ts +301 -0
- package/node_modules/mediabunny/dist/modules/src/input-format.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/input-format.js +701 -0
- package/node_modules/mediabunny/dist/modules/src/input-track.d.ts +571 -0
- package/node_modules/mediabunny/dist/modules/src/input-track.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/input-track.js +1179 -0
- package/node_modules/mediabunny/dist/modules/src/input.d.ts +183 -0
- package/node_modules/mediabunny/dist/modules/src/input.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/input.js +399 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-boxes.d.ts +216 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-boxes.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-boxes.js +1741 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-demuxer.d.ts +241 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-demuxer.js +3377 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-misc.d.ts +33 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-misc.js +51 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-muxer.d.ts +178 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-muxer.js +1320 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-reader.d.ts +23 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-reader.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/isobmff/isobmff-reader.js +72 -0
- package/node_modules/mediabunny/dist/modules/src/logging.d.ts +57 -0
- package/node_modules/mediabunny/dist/modules/src/logging.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/logging.js +84 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/ebml.d.ts +203 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/ebml.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/ebml.js +687 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-demuxer.d.ts +197 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-demuxer.js +2337 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-misc.d.ts +14 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-misc.js +20 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-muxer.d.ts +77 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/matroska/matroska-muxer.js +1157 -0
- package/node_modules/mediabunny/dist/modules/src/media-sink.d.ts +379 -0
- package/node_modules/mediabunny/dist/modules/src/media-sink.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/media-sink.js +2135 -0
- package/node_modules/mediabunny/dist/modules/src/media-source.d.ts +322 -0
- package/node_modules/mediabunny/dist/modules/src/media-source.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/media-source.js +2589 -0
- package/node_modules/mediabunny/dist/modules/src/metadata.d.ts +181 -0
- package/node_modules/mediabunny/dist/modules/src/metadata.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/metadata.js +206 -0
- package/node_modules/mediabunny/dist/modules/src/misc.d.ts +368 -0
- package/node_modules/mediabunny/dist/modules/src/misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/misc.js +1315 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-demuxer.d.ts +87 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-demuxer.js +347 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-muxer.d.ts +29 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-muxer.js +206 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-reader.d.ts +14 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-reader.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-reader.js +45 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-writer.d.ts +31 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-writer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/mp3/mp3-writer.js +79 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-demuxer.d.ts +102 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-demuxer.js +2034 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-misc.d.ts +27 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-misc.js +18 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-muxer.d.ts +47 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/mpeg-ts/mpeg-ts-muxer.js +644 -0
- package/node_modules/mediabunny/dist/modules/src/muxer.d.ts +26 -0
- package/node_modules/mediabunny/dist/modules/src/muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/muxer.js +42 -0
- package/node_modules/mediabunny/dist/modules/src/node.d.ts +9 -0
- package/node_modules/mediabunny/dist/modules/src/node.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/node.js +9 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-demuxer.d.ts +100 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-demuxer.js +837 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-misc.d.ts +27 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-misc.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-misc.js +78 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-muxer.d.ts +63 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-muxer.js +412 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-reader.d.ts +26 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-reader.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/ogg/ogg-reader.js +65 -0
- package/node_modules/mediabunny/dist/modules/src/output-format.d.ts +661 -0
- package/node_modules/mediabunny/dist/modules/src/output-format.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/output-format.js +828 -0
- package/node_modules/mediabunny/dist/modules/src/output.d.ts +343 -0
- package/node_modules/mediabunny/dist/modules/src/output.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/output.js +678 -0
- package/node_modules/mediabunny/dist/modules/src/packet.d.ts +139 -0
- package/node_modules/mediabunny/dist/modules/src/packet.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/packet.js +197 -0
- package/node_modules/mediabunny/dist/modules/src/pcm.d.ts +12 -0
- package/node_modules/mediabunny/dist/modules/src/pcm.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/pcm.js +88 -0
- package/node_modules/mediabunny/dist/modules/src/reader.d.ts +74 -0
- package/node_modules/mediabunny/dist/modules/src/reader.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/reader.js +288 -0
- package/node_modules/mediabunny/dist/modules/src/resample.d.ts +46 -0
- package/node_modules/mediabunny/dist/modules/src/resample.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/resample.js +259 -0
- package/node_modules/mediabunny/dist/modules/src/sample.d.ts +584 -0
- package/node_modules/mediabunny/dist/modules/src/sample.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/sample.js +2492 -0
- package/node_modules/mediabunny/dist/modules/src/segmented-input.d.ts +76 -0
- package/node_modules/mediabunny/dist/modules/src/segmented-input.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/segmented-input.js +403 -0
- package/node_modules/mediabunny/dist/modules/src/source.d.ts +372 -0
- package/node_modules/mediabunny/dist/modules/src/source.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/source.js +2058 -0
- package/node_modules/mediabunny/dist/modules/src/subtitles.d.ts +39 -0
- package/node_modules/mediabunny/dist/modules/src/subtitles.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/subtitles.js +121 -0
- package/node_modules/mediabunny/dist/modules/src/target.d.ts +193 -0
- package/node_modules/mediabunny/dist/modules/src/target.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/target.js +622 -0
- package/node_modules/mediabunny/dist/modules/src/tsconfig.tsbuildinfo +1 -0
- package/node_modules/mediabunny/dist/modules/src/version.d.ts +10 -0
- package/node_modules/mediabunny/dist/modules/src/version.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/version.js +10 -0
- package/node_modules/mediabunny/dist/modules/src/wave/riff-writer.d.ts +19 -0
- package/node_modules/mediabunny/dist/modules/src/wave/riff-writer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/wave/riff-writer.js +31 -0
- package/node_modules/mediabunny/dist/modules/src/wave/wave-demuxer.d.ts +86 -0
- package/node_modules/mediabunny/dist/modules/src/wave/wave-demuxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/wave/wave-demuxer.js +486 -0
- package/node_modules/mediabunny/dist/modules/src/wave/wave-muxer.d.ts +37 -0
- package/node_modules/mediabunny/dist/modules/src/wave/wave-muxer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/wave/wave-muxer.js +334 -0
- package/node_modules/mediabunny/dist/modules/src/writer.d.ts +37 -0
- package/node_modules/mediabunny/dist/modules/src/writer.d.ts.map +1 -0
- package/node_modules/mediabunny/dist/modules/src/writer.js +100 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/LICENSE +21 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/README.md +15 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/index.d.ts +115 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/node_modules/@types/dom-webcodecs/LICENSE +21 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/node_modules/@types/dom-webcodecs/README.md +15 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/node_modules/@types/dom-webcodecs/index.d.ts +185 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/node_modules/@types/dom-webcodecs/package.json +26 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/node_modules/@types/dom-webcodecs/webcodecs.generated.d.ts +517 -0
- package/node_modules/mediabunny/node_modules/@types/dom-mediacapture-transform/package.json +29 -0
- package/node_modules/mediabunny/node_modules/@types/dom-webcodecs/LICENSE +21 -0
- package/node_modules/mediabunny/node_modules/@types/dom-webcodecs/README.md +15 -0
- package/node_modules/mediabunny/node_modules/@types/dom-webcodecs/index.d.ts +185 -0
- package/node_modules/mediabunny/node_modules/@types/dom-webcodecs/package.json +26 -0
- package/node_modules/mediabunny/node_modules/@types/dom-webcodecs/webcodecs.generated.d.ts +517 -0
- package/node_modules/mediabunny/package.json +136 -0
- package/node_modules/mediabunny/src/adts/adts-demuxer.ts +401 -0
- package/node_modules/mediabunny/src/adts/adts-muxer.ts +129 -0
- package/node_modules/mediabunny/src/adts/adts-reader.ts +85 -0
- package/node_modules/mediabunny/src/aes.ts +307 -0
- package/node_modules/mediabunny/src/codec-data.ts +3842 -0
- package/node_modules/mediabunny/src/codec.ts +1348 -0
- package/node_modules/mediabunny/src/conversion.ts +2511 -0
- package/node_modules/mediabunny/src/custom-coder.ts +212 -0
- package/node_modules/mediabunny/src/decode.ts +263 -0
- package/node_modules/mediabunny/src/demuxer.ts +43 -0
- package/node_modules/mediabunny/src/encode.ts +1484 -0
- package/node_modules/mediabunny/src/flac/flac-demuxer.ts +814 -0
- package/node_modules/mediabunny/src/flac/flac-misc.ts +165 -0
- package/node_modules/mediabunny/src/flac/flac-muxer.ts +383 -0
- package/node_modules/mediabunny/src/hls/hls-demuxer.ts +964 -0
- package/node_modules/mediabunny/src/hls/hls-misc.ts +188 -0
- package/node_modules/mediabunny/src/hls/hls-muxer.ts +1727 -0
- package/node_modules/mediabunny/src/hls/hls-segmented-input.ts +781 -0
- package/node_modules/mediabunny/src/id3.ts +988 -0
- package/node_modules/mediabunny/src/index.ts +324 -0
- package/node_modules/mediabunny/src/input-format.ts +852 -0
- package/node_modules/mediabunny/src/input-track.ts +1655 -0
- package/node_modules/mediabunny/src/input.ts +574 -0
- package/node_modules/mediabunny/src/isobmff/isobmff-boxes.ts +2055 -0
- package/node_modules/mediabunny/src/isobmff/isobmff-demuxer.ts +4176 -0
- package/node_modules/mediabunny/src/isobmff/isobmff-misc.ts +90 -0
- package/node_modules/mediabunny/src/isobmff/isobmff-muxer.ts +1832 -0
- package/node_modules/mediabunny/src/isobmff/isobmff-reader.ts +91 -0
- package/node_modules/mediabunny/src/logging.ts +120 -0
- package/node_modules/mediabunny/src/matroska/ebml.ts +774 -0
- package/node_modules/mediabunny/src/matroska/matroska-demuxer.ts +2737 -0
- package/node_modules/mediabunny/src/matroska/matroska-misc.ts +29 -0
- package/node_modules/mediabunny/src/matroska/matroska-muxer.ts +1465 -0
- package/node_modules/mediabunny/src/media-sink.ts +2708 -0
- package/node_modules/mediabunny/src/media-source.ts +3203 -0
- package/node_modules/mediabunny/src/metadata.ts +347 -0
- package/node_modules/mediabunny/src/misc.ts +1721 -0
- package/node_modules/mediabunny/src/mp3/mp3-demuxer.ts +484 -0
- package/node_modules/mediabunny/src/mp3/mp3-muxer.ts +268 -0
- package/node_modules/mediabunny/src/mp3/mp3-reader.ts +62 -0
- package/node_modules/mediabunny/src/mp3/mp3-writer.ts +123 -0
- package/node_modules/mediabunny/src/mpeg-ts/mpeg-ts-demuxer.ts +2745 -0
- package/node_modules/mediabunny/src/mpeg-ts/mpeg-ts-misc.ts +38 -0
- package/node_modules/mediabunny/src/mpeg-ts/mpeg-ts-muxer.ts +857 -0
- package/node_modules/mediabunny/src/muxer.ts +76 -0
- package/node_modules/mediabunny/src/node.ts +11 -0
- package/node_modules/mediabunny/src/ogg/ogg-demuxer.ts +1157 -0
- package/node_modules/mediabunny/src/ogg/ogg-misc.ts +116 -0
- package/node_modules/mediabunny/src/ogg/ogg-muxer.ts +579 -0
- package/node_modules/mediabunny/src/ogg/ogg-reader.ts +93 -0
- package/node_modules/mediabunny/src/output-format.ts +1502 -0
- package/node_modules/mediabunny/src/output.ts +1051 -0
- package/node_modules/mediabunny/src/packet.ts +287 -0
- package/node_modules/mediabunny/src/pcm.ts +114 -0
- package/node_modules/mediabunny/src/reader.ts +391 -0
- package/node_modules/mediabunny/src/resample.ts +305 -0
- package/node_modules/mediabunny/src/sample.ts +3460 -0
- package/node_modules/mediabunny/src/segmented-input.ts +611 -0
- package/node_modules/mediabunny/src/source.ts +2866 -0
- package/node_modules/mediabunny/src/subtitles.ts +172 -0
- package/node_modules/mediabunny/src/target.ts +882 -0
- package/node_modules/mediabunny/src/tsconfig.json +16 -0
- package/node_modules/mediabunny/src/version.ts +13 -0
- package/node_modules/mediabunny/src/wave/riff-writer.ts +37 -0
- package/node_modules/mediabunny/src/wave/wave-demuxer.ts +583 -0
- package/node_modules/mediabunny/src/wave/wave-muxer.ts +394 -0
- package/node_modules/mediabunny/src/writer.ts +128 -0
- package/package.json +20 -7
- package/types/api.d.ts +4 -215
- package/types/extension-v2.d.ts +6 -2
- package/types/extension-v2.type-test.ts +1 -1
- package/types/extension-v3.d.ts +1059 -0
- package/types/extension-v3.type-test.ts +670 -0
- package/types/extension.d.ts +4 -0
- package/types/feedback.d.ts +2 -0
- package/types/manifest.d.ts +89 -39
- package/types/runtime.d.ts +270 -0
- package/types/v2.d.ts +20 -0
- package/types/vitest.d.ts +13 -0
- package/dist/build-BKPG8Cjv.mjs +0 -1
- package/dist/build-shared-CTIqtE6C.mjs +0 -1
- package/dist/config-CBQcinVg.mjs +0 -18
- package/dist/context-CA1V7xGS.mjs +0 -131
- package/dist/dev-Diyb9wJU.mjs +0 -1
- package/dist/dist-B7sKLAn9.mjs +0 -27
- package/dist/dist-CPqT8wsb.mjs +0 -21
- package/dist/dist-DWac1F1m.mjs +0 -1
- package/dist/dist-l2ujm0Ay.mjs +0 -7
- package/dist/filename-DQnUJlio-Dxkwi2LB.mjs +0 -38
- package/dist/logger-C_MCwmRJ.mjs +0 -18
- package/dist/node-CJGbmw8A.mjs +0 -3
- package/dist/prompt-U5ajztzG-vUDxm337.mjs +0 -45
- package/dist/resolver-DkvdaW3s-B5R6Y3j5.mjs +0 -1
- package/dist/tsc-CILA0DAV.mjs +0 -1
- package/dist/tsc-context-BP5ZtADe.mjs +0 -1
- /package/dist/{detect-DN3DXXYt-DoVMOyS2.mjs → detect-DN3DXXYt-C0EBpmu-.mjs} +0 -0
- /package/dist/{open-LYR5RfQA.mjs → open-A5xG8fyK.mjs} +0 -0
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2026-present, Vanilagy and contributors
|
|
3
|
+
*
|
|
4
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { FileHandle } from 'node:fs/promises';
|
|
10
|
+
import * as nodeAlias from './node';
|
|
11
|
+
import { assert, EventEmitter, FilePath, isWebKit, MaybePromise } from './misc';
|
|
12
|
+
|
|
13
|
+
const node = typeof nodeAlias !== 'undefined'
|
|
14
|
+
? nodeAlias // Aliasing it prevents some bundler warnings
|
|
15
|
+
: undefined!;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The events emitted by a {@link Target}.
|
|
19
|
+
* @group Output targets
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export type TargetEvents = {
|
|
23
|
+
/** Emitted each time data is written to the target. */
|
|
24
|
+
write: {
|
|
25
|
+
/** The start of the written range, inclusive. */
|
|
26
|
+
start: number;
|
|
27
|
+
/** The end of the written range, exclusive. */
|
|
28
|
+
end: number;
|
|
29
|
+
};
|
|
30
|
+
/** Emitted when the target is finalized. */
|
|
31
|
+
finalized: void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Base class for targets, specifying where output files are written.
|
|
36
|
+
* @group Output targets
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export abstract class Target extends EventEmitter<TargetEvents> {
|
|
40
|
+
/** @internal */
|
|
41
|
+
_writerAcquired = false;
|
|
42
|
+
|
|
43
|
+
/** @internal */
|
|
44
|
+
_monotonicity: boolean | null = null; // null = unknown
|
|
45
|
+
|
|
46
|
+
/** @internal */
|
|
47
|
+
abstract _start(): void;
|
|
48
|
+
/** @internal */
|
|
49
|
+
abstract _write(data: Uint8Array, pos: number): void;
|
|
50
|
+
/** @internal */
|
|
51
|
+
abstract _flush(): Promise<void>;
|
|
52
|
+
/** @internal */
|
|
53
|
+
abstract _finalize(): Promise<void>;
|
|
54
|
+
/** @internal */
|
|
55
|
+
abstract _close(): Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Called each time data is written to the target. Will be called with the byte range into which data was written.
|
|
59
|
+
*
|
|
60
|
+
* Use this callback to track the size of the output file as it grows. But be warned, this function is chatty and
|
|
61
|
+
* gets called *extremely* often.
|
|
62
|
+
*
|
|
63
|
+
* @deprecated Use `target.on('write', ({ start, end }) => ...)` instead.
|
|
64
|
+
*/
|
|
65
|
+
onwrite: ((start: number, end: number) => unknown) | null = null;
|
|
66
|
+
|
|
67
|
+
/** @internal */
|
|
68
|
+
_setMonotonicity(monotonicity: boolean) {
|
|
69
|
+
if (this._monotonicity !== false) {
|
|
70
|
+
this._monotonicity = monotonicity;
|
|
71
|
+
} else {
|
|
72
|
+
// Once false, it's locked
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @internal */
|
|
77
|
+
_dispatchWrite(start: number, end: number) {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
79
|
+
this.onwrite?.(start, end);
|
|
80
|
+
this._emit('write', { start, end });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns a new {@link RangedTarget} that writes data to this target using the given offset.
|
|
85
|
+
*
|
|
86
|
+
* Useful for writing a file into a section of a larger file.
|
|
87
|
+
*/
|
|
88
|
+
slice(offset: number) {
|
|
89
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
90
|
+
throw new TypeError('offset must be a non-negative integer.');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return new RangedTarget(this, offset);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const ARRAY_BUFFER_INITIAL_SIZE = 2 ** 16;
|
|
98
|
+
const ARRAY_BUFFER_MAX_SIZE = 2 ** 32;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Options for {@link BufferTarget}.
|
|
102
|
+
* @group Output targets
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export type BufferTargetOptions = {
|
|
106
|
+
/**
|
|
107
|
+
* Called once the target has been finalized, with the complete output buffer. If you return a promise, it will be
|
|
108
|
+
* used to apply backpressure internally.
|
|
109
|
+
*
|
|
110
|
+
* One use for this callback is for uploading to a server where the full buffer must be known before
|
|
111
|
+
* sending (e.g. S3 PutObject) and stream-uploading is not an option.
|
|
112
|
+
*/
|
|
113
|
+
onFinalize?: (buffer: ArrayBuffer) => MaybePromise<unknown>;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A target that writes data directly into an ArrayBuffer in memory. Great for performance, but not suitable for very
|
|
118
|
+
* large files. The buffer will be available once the output has been finalized.
|
|
119
|
+
* @group Output targets
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
export class BufferTarget extends Target {
|
|
123
|
+
/** Stores the final output buffer. Until the output is finalized, this will be `null`. */
|
|
124
|
+
buffer: ArrayBuffer | null = null;
|
|
125
|
+
|
|
126
|
+
/** @internal */
|
|
127
|
+
_buffer: ArrayBuffer;
|
|
128
|
+
/** @internal */
|
|
129
|
+
_bytes: Uint8Array;
|
|
130
|
+
/** @internal */
|
|
131
|
+
_maxPos = 0;
|
|
132
|
+
/** @internal */
|
|
133
|
+
_supportsResize: boolean;
|
|
134
|
+
/** @internal */
|
|
135
|
+
_options: BufferTargetOptions;
|
|
136
|
+
|
|
137
|
+
/** Creates a new {@link BufferTarget}. The buffer holding the data will be created and managed internally. */
|
|
138
|
+
constructor(options: BufferTargetOptions = {}) {
|
|
139
|
+
super();
|
|
140
|
+
|
|
141
|
+
if (!options || typeof options !== 'object') {
|
|
142
|
+
throw new TypeError('BufferTarget options, when provided, must be an object.');
|
|
143
|
+
}
|
|
144
|
+
if (options.onFinalize !== undefined && typeof options.onFinalize !== 'function') {
|
|
145
|
+
throw new TypeError('options.onFinalize, when provided, must be a function.');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
this._options = options;
|
|
149
|
+
|
|
150
|
+
this._supportsResize = 'resize' in new ArrayBuffer(0);
|
|
151
|
+
if (this._supportsResize) {
|
|
152
|
+
try {
|
|
153
|
+
// @ts-expect-error Don't want to bump "lib" in tsconfig
|
|
154
|
+
this._buffer = new ArrayBuffer(ARRAY_BUFFER_INITIAL_SIZE, { maxByteLength: ARRAY_BUFFER_MAX_SIZE });
|
|
155
|
+
} catch {
|
|
156
|
+
this._buffer = new ArrayBuffer(ARRAY_BUFFER_INITIAL_SIZE);
|
|
157
|
+
this._supportsResize = false;
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
this._buffer = new ArrayBuffer(ARRAY_BUFFER_INITIAL_SIZE);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this._bytes = new Uint8Array(this._buffer);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @internal */
|
|
167
|
+
_ensureSize(size: number) {
|
|
168
|
+
let newLength = this._buffer.byteLength;
|
|
169
|
+
while (newLength < size) newLength *= 2;
|
|
170
|
+
|
|
171
|
+
if (newLength === this._buffer.byteLength) return;
|
|
172
|
+
|
|
173
|
+
if (newLength > ARRAY_BUFFER_MAX_SIZE) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`ArrayBuffer exceeded maximum size of ${ARRAY_BUFFER_MAX_SIZE} bytes. Please consider using another`
|
|
176
|
+
+ ` target.`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (this._supportsResize) {
|
|
181
|
+
// Use resize if it exists
|
|
182
|
+
// @ts-expect-error Don't want to bump "lib" in tsconfig
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
184
|
+
this._buffer.resize(newLength);
|
|
185
|
+
// The Uint8Array scales automatically
|
|
186
|
+
} else {
|
|
187
|
+
const newBuffer = new ArrayBuffer(newLength);
|
|
188
|
+
const newBytes = new Uint8Array(newBuffer);
|
|
189
|
+
newBytes.set(this._bytes, 0);
|
|
190
|
+
|
|
191
|
+
this._buffer = newBuffer;
|
|
192
|
+
this._bytes = newBytes;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** @internal */
|
|
197
|
+
_start() {}
|
|
198
|
+
|
|
199
|
+
/** @internal */
|
|
200
|
+
_write(data: Uint8Array, pos: number) {
|
|
201
|
+
this._ensureSize(pos + data.byteLength);
|
|
202
|
+
|
|
203
|
+
this._bytes.set(data, pos);
|
|
204
|
+
|
|
205
|
+
this._maxPos = Math.max(this._maxPos, pos + data.byteLength);
|
|
206
|
+
|
|
207
|
+
this._dispatchWrite(pos, pos + data.byteLength);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** @internal */
|
|
211
|
+
async _flush() {}
|
|
212
|
+
|
|
213
|
+
/** @internal */
|
|
214
|
+
async _finalize() {
|
|
215
|
+
this.buffer = this._buffer.slice(0, this._maxPos);
|
|
216
|
+
|
|
217
|
+
if (this._options.onFinalize) {
|
|
218
|
+
await this._options.onFinalize(this.buffer);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this._emit('finalized');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** @internal */
|
|
225
|
+
async _close() {}
|
|
226
|
+
|
|
227
|
+
/** @internal */
|
|
228
|
+
_getSlice(start: number, end: number) {
|
|
229
|
+
return this._bytes.slice(start, end);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A data chunk for {@link StreamTarget}.
|
|
235
|
+
* @group Output targets
|
|
236
|
+
* @public
|
|
237
|
+
*/
|
|
238
|
+
export type StreamTargetChunk = {
|
|
239
|
+
/** The operation type. */
|
|
240
|
+
type: 'write'; // This ensures automatic compatibility with FileSystemWritableFileStream
|
|
241
|
+
/** The data to write. */
|
|
242
|
+
data: Uint8Array<ArrayBuffer>;
|
|
243
|
+
/** The byte offset in the output file at which to write the data. */
|
|
244
|
+
position: number;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Options for {@link StreamTarget}.
|
|
249
|
+
* @group Output targets
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
export type StreamTargetOptions = {
|
|
253
|
+
/**
|
|
254
|
+
* When setting this to true, data created by the output will first be accumulated and only written out
|
|
255
|
+
* once it has reached sufficient size, using a default chunk size of 16 MiB. This is useful for reducing the total
|
|
256
|
+
* amount of writes, at the cost of latency.
|
|
257
|
+
*/
|
|
258
|
+
chunked?: boolean;
|
|
259
|
+
/** When using `chunked: true`, this specifies the maximum size of each chunk. Defaults to 16 MiB. */
|
|
260
|
+
chunkSize?: number;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const DEFAULT_CHUNK_SIZE = 2 ** 24;
|
|
264
|
+
const MAX_CHUNKS_AT_ONCE = 2;
|
|
265
|
+
|
|
266
|
+
type Chunk = {
|
|
267
|
+
start: number;
|
|
268
|
+
written: ChunkSection[];
|
|
269
|
+
data: Uint8Array<ArrayBuffer>;
|
|
270
|
+
shouldFlush: boolean;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
type ChunkSection = {
|
|
274
|
+
start: number;
|
|
275
|
+
end: number;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* This target writes data to a [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream),
|
|
280
|
+
* making it a general-purpose target for writing data anywhere. It is also compatible with
|
|
281
|
+
* [`FileSystemWritableFileStream`](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream) for
|
|
282
|
+
* use with the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API). The
|
|
283
|
+
* `WritableStream` can also apply backpressure, which will propagate to the output and throttle the encoders.
|
|
284
|
+
* @group Output targets
|
|
285
|
+
* @public
|
|
286
|
+
*/
|
|
287
|
+
export class StreamTarget extends Target {
|
|
288
|
+
/** @internal */
|
|
289
|
+
_writable: WritableStream<StreamTargetChunk>;
|
|
290
|
+
/** @internal */
|
|
291
|
+
_options: StreamTargetOptions;
|
|
292
|
+
|
|
293
|
+
/** @internal */
|
|
294
|
+
_sections: {
|
|
295
|
+
data: Uint8Array;
|
|
296
|
+
start: number;
|
|
297
|
+
}[] = [];
|
|
298
|
+
|
|
299
|
+
/** @internal */
|
|
300
|
+
_lastWriteEnd = 0;
|
|
301
|
+
/** @internal */
|
|
302
|
+
_lastFlushEnd = 0;
|
|
303
|
+
/** @internal */
|
|
304
|
+
_streamWriter: WritableStreamDefaultWriter<StreamTargetChunk> | null = null;
|
|
305
|
+
/** @internal */
|
|
306
|
+
_writeError: unknown = null;
|
|
307
|
+
|
|
308
|
+
// These variables regard chunked mode:
|
|
309
|
+
/** @internal */
|
|
310
|
+
_chunked: boolean;
|
|
311
|
+
/** @internal */
|
|
312
|
+
_chunkSize: number;
|
|
313
|
+
/**
|
|
314
|
+
* The data is divided up into fixed-size chunks, whose contents are first filled in RAM and then flushed out.
|
|
315
|
+
* A chunk is flushed if all of its contents have been written.
|
|
316
|
+
*/
|
|
317
|
+
/** @internal */
|
|
318
|
+
_chunks: Chunk[] = [];
|
|
319
|
+
|
|
320
|
+
/** Creates a new {@link StreamTarget} which writes to the specified `writable`. */
|
|
321
|
+
constructor(
|
|
322
|
+
writable: WritableStream<StreamTargetChunk>,
|
|
323
|
+
options: StreamTargetOptions = {},
|
|
324
|
+
) {
|
|
325
|
+
super();
|
|
326
|
+
|
|
327
|
+
if (!(writable instanceof WritableStream)) {
|
|
328
|
+
throw new TypeError('StreamTarget requires a WritableStream instance.');
|
|
329
|
+
}
|
|
330
|
+
if (options != null && typeof options !== 'object') {
|
|
331
|
+
throw new TypeError('StreamTarget options, when provided, must be an object.');
|
|
332
|
+
}
|
|
333
|
+
if (options.chunked !== undefined && typeof options.chunked !== 'boolean') {
|
|
334
|
+
throw new TypeError('options.chunked, when provided, must be a boolean.');
|
|
335
|
+
}
|
|
336
|
+
if (options.chunkSize !== undefined && (!Number.isInteger(options.chunkSize) || options.chunkSize < 1024)) {
|
|
337
|
+
throw new TypeError('options.chunkSize, when provided, must be an integer and not smaller than 1024.');
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
this._writable = writable;
|
|
341
|
+
this._options = options;
|
|
342
|
+
|
|
343
|
+
this._chunked = options.chunked ?? false;
|
|
344
|
+
this._chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** @internal */
|
|
348
|
+
_start() {
|
|
349
|
+
this._streamWriter = this._writable.getWriter();
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** @internal */
|
|
353
|
+
_write(data: Uint8Array, pos: number) {
|
|
354
|
+
if (pos > this._lastWriteEnd) {
|
|
355
|
+
const paddingBytesNeeded = pos - this._lastWriteEnd;
|
|
356
|
+
this._write(new Uint8Array(paddingBytesNeeded), this._lastWriteEnd);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
this._sections.push({
|
|
360
|
+
data: data.slice(),
|
|
361
|
+
start: pos,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
this._lastWriteEnd = Math.max(this._lastWriteEnd, pos + data.byteLength);
|
|
365
|
+
|
|
366
|
+
this._dispatchWrite(pos, pos + data.byteLength);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** @internal */
|
|
370
|
+
async _flush() {
|
|
371
|
+
if (this._writeError !== null) {
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
373
|
+
throw this._writeError;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
assert(this._streamWriter);
|
|
377
|
+
|
|
378
|
+
if (this._sections.length === 0) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const chunks: {
|
|
383
|
+
start: number;
|
|
384
|
+
size: number;
|
|
385
|
+
data?: Uint8Array<ArrayBuffer>;
|
|
386
|
+
}[] = [];
|
|
387
|
+
const sorted = [...this._sections].sort((a, b) => a.start - b.start);
|
|
388
|
+
|
|
389
|
+
chunks.push({
|
|
390
|
+
start: sorted[0]!.start,
|
|
391
|
+
size: sorted[0]!.data.byteLength,
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
// Figure out how many contiguous chunks we have
|
|
395
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
396
|
+
const lastChunk = chunks[chunks.length - 1]!;
|
|
397
|
+
const section = sorted[i]!;
|
|
398
|
+
|
|
399
|
+
if (section.start <= lastChunk.start + lastChunk.size) {
|
|
400
|
+
lastChunk.size = Math.max(lastChunk.size, section.start + section.data.byteLength - lastChunk.start);
|
|
401
|
+
} else {
|
|
402
|
+
chunks.push({
|
|
403
|
+
start: section.start,
|
|
404
|
+
size: section.data.byteLength,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
for (const chunk of chunks) {
|
|
410
|
+
chunk.data = new Uint8Array(chunk.size);
|
|
411
|
+
|
|
412
|
+
// Make sure to write the data in the correct order for correct overwriting
|
|
413
|
+
for (const section of this._sections) {
|
|
414
|
+
// Check if the section is in the chunk
|
|
415
|
+
if (chunk.start <= section.start && section.start < chunk.start + chunk.size) {
|
|
416
|
+
chunk.data.set(section.data, section.start - chunk.start);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (this._streamWriter.desiredSize !== null && this._streamWriter.desiredSize <= 0) {
|
|
421
|
+
await this._streamWriter.ready; // Allow the writer to apply backpressure
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (this._chunked) {
|
|
425
|
+
// Let's first gather the data into bigger chunks before writing it
|
|
426
|
+
this._writeDataIntoChunks(chunk.data, chunk.start);
|
|
427
|
+
this._tryToFlushChunks();
|
|
428
|
+
} else {
|
|
429
|
+
if (this._monotonicity === true && chunk.start !== this._lastFlushEnd) {
|
|
430
|
+
throw new Error('Internal error: Monotonicity violation.');
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
void this._streamWriter.write({
|
|
434
|
+
type: 'write',
|
|
435
|
+
data: chunk.data,
|
|
436
|
+
position: chunk.start,
|
|
437
|
+
}).catch((error) => {
|
|
438
|
+
this._writeError ??= error;
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
this._lastFlushEnd = chunk.start + chunk.data.byteLength;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
this._sections.length = 0;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** @internal */
|
|
449
|
+
_writeDataIntoChunks(data: Uint8Array, position: number) {
|
|
450
|
+
// First, find the chunk to write the data into, or create one if none exists
|
|
451
|
+
let chunkIndex = this._chunks.findIndex(x => x.start <= position && position < x.start + this._chunkSize);
|
|
452
|
+
if (chunkIndex === -1) chunkIndex = this._createChunk(position);
|
|
453
|
+
const chunk = this._chunks[chunkIndex]!;
|
|
454
|
+
|
|
455
|
+
// Figure out how much to write to the chunk, and then write to the chunk
|
|
456
|
+
const relativePosition = position - chunk.start;
|
|
457
|
+
const toWrite = data.subarray(0, Math.min(this._chunkSize - relativePosition, data.byteLength));
|
|
458
|
+
chunk.data.set(toWrite, relativePosition);
|
|
459
|
+
|
|
460
|
+
// Create a section describing the region of data that was just written to
|
|
461
|
+
const section: ChunkSection = {
|
|
462
|
+
start: relativePosition,
|
|
463
|
+
end: relativePosition + toWrite.byteLength,
|
|
464
|
+
};
|
|
465
|
+
this._insertSectionIntoChunk(chunk, section);
|
|
466
|
+
|
|
467
|
+
// Queue chunk for flushing to target if it has been fully written to
|
|
468
|
+
if (chunk.written[0]!.start === 0 && chunk.written[0]!.end === this._chunkSize) {
|
|
469
|
+
chunk.shouldFlush = true;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// Make sure we don't hold too many chunks in memory at once to keep memory usage down
|
|
473
|
+
if (this._chunks.length > MAX_CHUNKS_AT_ONCE) {
|
|
474
|
+
// Flush all but the last chunk
|
|
475
|
+
for (let i = 0; i < this._chunks.length - 1; i++) {
|
|
476
|
+
this._chunks[i]!.shouldFlush = true;
|
|
477
|
+
}
|
|
478
|
+
this._tryToFlushChunks();
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// If the data didn't fit in one chunk, recurse with the remaining data
|
|
482
|
+
if (toWrite.byteLength < data.byteLength) {
|
|
483
|
+
this._writeDataIntoChunks(data.subarray(toWrite.byteLength), position + toWrite.byteLength);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** @internal */
|
|
488
|
+
_insertSectionIntoChunk(chunk: Chunk, section: ChunkSection) {
|
|
489
|
+
let low = 0;
|
|
490
|
+
let high = chunk.written.length - 1;
|
|
491
|
+
let index = -1;
|
|
492
|
+
|
|
493
|
+
// Do a binary search to find the last section with a start not larger than `section`'s start
|
|
494
|
+
while (low <= high) {
|
|
495
|
+
const mid = Math.floor(low + (high - low + 1) / 2);
|
|
496
|
+
|
|
497
|
+
if (chunk.written[mid]!.start <= section.start) {
|
|
498
|
+
low = mid + 1;
|
|
499
|
+
index = mid;
|
|
500
|
+
} else {
|
|
501
|
+
high = mid - 1;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Insert the new section
|
|
506
|
+
chunk.written.splice(index + 1, 0, section);
|
|
507
|
+
if (index === -1 || chunk.written[index]!.end < section.start) index++;
|
|
508
|
+
|
|
509
|
+
// Merge overlapping sections
|
|
510
|
+
while (index < chunk.written.length - 1 && chunk.written[index]!.end >= chunk.written[index + 1]!.start) {
|
|
511
|
+
chunk.written[index]!.end = Math.max(chunk.written[index]!.end, chunk.written[index + 1]!.end);
|
|
512
|
+
chunk.written.splice(index + 1, 1);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** @internal */
|
|
517
|
+
_createChunk(includesPosition: number) {
|
|
518
|
+
const start = Math.floor(includesPosition / this._chunkSize) * this._chunkSize;
|
|
519
|
+
const chunk: Chunk = {
|
|
520
|
+
start,
|
|
521
|
+
data: new Uint8Array(this._chunkSize),
|
|
522
|
+
written: [],
|
|
523
|
+
shouldFlush: false,
|
|
524
|
+
};
|
|
525
|
+
this._chunks.push(chunk);
|
|
526
|
+
this._chunks.sort((a, b) => a.start - b.start);
|
|
527
|
+
|
|
528
|
+
return this._chunks.indexOf(chunk);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** @internal */
|
|
532
|
+
_tryToFlushChunks(force = false) {
|
|
533
|
+
assert(this._streamWriter);
|
|
534
|
+
|
|
535
|
+
for (let i = 0; i < this._chunks.length; i++) {
|
|
536
|
+
const chunk = this._chunks[i]!;
|
|
537
|
+
if (!chunk.shouldFlush && !force) continue;
|
|
538
|
+
|
|
539
|
+
for (const section of chunk.written) {
|
|
540
|
+
const position = chunk.start + section.start;
|
|
541
|
+
if (this._monotonicity === true && position !== this._lastFlushEnd) {
|
|
542
|
+
throw new Error('Internal error: Monotonicity violation.');
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const isPartialView = section.start !== 0 || section.end !== chunk.data.byteLength;
|
|
546
|
+
|
|
547
|
+
let data: Uint8Array<ArrayBuffer>;
|
|
548
|
+
if (isPartialView && isWebKit()) {
|
|
549
|
+
// https://bugs.webkit.org/show_bug.cgi?id=302733
|
|
550
|
+
data = chunk.data.slice(section.start, section.end);
|
|
551
|
+
} else {
|
|
552
|
+
data = chunk.data.subarray(section.start, section.end);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
void this._streamWriter.write({
|
|
556
|
+
type: 'write',
|
|
557
|
+
data,
|
|
558
|
+
position,
|
|
559
|
+
}).catch((error) => {
|
|
560
|
+
this._writeError ??= error;
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
this._lastFlushEnd = chunk.start + section.end;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
this._chunks.splice(i--, 1);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/** @internal */
|
|
571
|
+
async _finalize() {
|
|
572
|
+
if (this._chunked) {
|
|
573
|
+
this._tryToFlushChunks(true);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (this._writeError !== null) {
|
|
577
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
578
|
+
throw this._writeError;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
assert(this._streamWriter);
|
|
582
|
+
await this._streamWriter.ready;
|
|
583
|
+
await this._streamWriter.close();
|
|
584
|
+
|
|
585
|
+
this._emit('finalized');
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/** @internal */
|
|
589
|
+
async _close() {
|
|
590
|
+
return this._streamWriter?.close();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* This target writes to a `WritableStream<Uint8Array>`, meaning all writes are necessarily append-only and involve no
|
|
596
|
+
* seeking. Great for streaming data to a source that can only accept sequential data, like an HTTP server processing
|
|
597
|
+
* an incoming upload.
|
|
598
|
+
*
|
|
599
|
+
* Note that using this target *requires* that the underlying format write data sequentially. Not all formats do this,
|
|
600
|
+
* and this target will throw for the formats that don't. Check the guide for more.
|
|
601
|
+
*
|
|
602
|
+
* @group Output targets
|
|
603
|
+
* @public
|
|
604
|
+
*/
|
|
605
|
+
export class AppendOnlyStreamTarget extends Target {
|
|
606
|
+
/** @internal */
|
|
607
|
+
_writable: WritableStream<Uint8Array>;
|
|
608
|
+
/** @internal */
|
|
609
|
+
_streamTarget: StreamTarget;
|
|
610
|
+
/** @internal */
|
|
611
|
+
_writer: WritableStreamDefaultWriter<Uint8Array> | null = null;
|
|
612
|
+
/** @internal */
|
|
613
|
+
_nextWritePos = 0;
|
|
614
|
+
|
|
615
|
+
constructor(writable: WritableStream<Uint8Array>) {
|
|
616
|
+
super();
|
|
617
|
+
|
|
618
|
+
this._writable = writable;
|
|
619
|
+
this._streamTarget = new StreamTarget(new WritableStream({
|
|
620
|
+
start: () => {
|
|
621
|
+
this._writer = this._writable.getWriter();
|
|
622
|
+
},
|
|
623
|
+
write: (chunk) => {
|
|
624
|
+
if (this._monotonicity !== true) {
|
|
625
|
+
throw new Error(
|
|
626
|
+
'AppendOnlyStreamTarget requires that data be written monotonically (always appended to the'
|
|
627
|
+
+ ' end). You must use a format that guarantees this behavior.',
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
assert(chunk.position === this._nextWritePos);
|
|
632
|
+
this._nextWritePos += chunk.data.byteLength;
|
|
633
|
+
|
|
634
|
+
assert(this._writer);
|
|
635
|
+
return this._writer.write(chunk.data);
|
|
636
|
+
},
|
|
637
|
+
close: () => {
|
|
638
|
+
return this._writer?.close();
|
|
639
|
+
},
|
|
640
|
+
}));
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/** @internal */
|
|
644
|
+
_start(): void {
|
|
645
|
+
this._streamTarget._start();
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** @internal */
|
|
649
|
+
_write(data: Uint8Array, pos: number): void {
|
|
650
|
+
this._streamTarget._write(data, pos);
|
|
651
|
+
this._dispatchWrite(pos, pos + data.byteLength);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/** @internal */
|
|
655
|
+
_flush(): Promise<void> {
|
|
656
|
+
return this._streamTarget._flush();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** @internal */
|
|
660
|
+
_finalize(): Promise<void> {
|
|
661
|
+
return this._streamTarget._finalize();
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** @internal */
|
|
665
|
+
_close(): Promise<void> {
|
|
666
|
+
return this._streamTarget._close();
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** @internal */
|
|
670
|
+
override _setMonotonicity(monotonicity: boolean): void {
|
|
671
|
+
super._setMonotonicity(monotonicity);
|
|
672
|
+
this._streamTarget._setMonotonicity(monotonicity);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Options for {@link FilePathTarget}.
|
|
678
|
+
* @group Output targets
|
|
679
|
+
* @public
|
|
680
|
+
*/
|
|
681
|
+
export type FilePathTargetOptions = StreamTargetOptions;
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* A target that writes to a file at the specified path. Intended for server-side usage in Node, Bun, or Deno.
|
|
685
|
+
*
|
|
686
|
+
* Writing is chunked by default. The internally held file handle will be closed when `.finalize()` or `.cancel()` are
|
|
687
|
+
* called on the corresponding {@link Output}.
|
|
688
|
+
* @group Output targets
|
|
689
|
+
* @public
|
|
690
|
+
*/
|
|
691
|
+
export class FilePathTarget extends Target {
|
|
692
|
+
/** @internal */
|
|
693
|
+
_streamTarget: StreamTarget;
|
|
694
|
+
/** @internal */
|
|
695
|
+
_fileHandle: FileHandle | null = null;
|
|
696
|
+
|
|
697
|
+
/** Creates a new {@link FilePathTarget} that writes to the file at the specified file path. */
|
|
698
|
+
constructor(filePath: string, options: FilePathTargetOptions = {}) {
|
|
699
|
+
if (typeof filePath !== 'string') {
|
|
700
|
+
throw new TypeError('filePath must be a string.');
|
|
701
|
+
}
|
|
702
|
+
if (!options || typeof options !== 'object') {
|
|
703
|
+
throw new TypeError('options must be an object.');
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
if (!node.fs) {
|
|
707
|
+
throw new Error(
|
|
708
|
+
'FilePathTarget is only available in server-side environments (Node.js, Bun, Deno).',
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
super();
|
|
713
|
+
|
|
714
|
+
// Let's back this target with a StreamTarget, makes the implementation very simple
|
|
715
|
+
const writable = new WritableStream<StreamTargetChunk>({
|
|
716
|
+
start: async () => {
|
|
717
|
+
this._fileHandle = await node.fs.open(filePath, 'w');
|
|
718
|
+
},
|
|
719
|
+
write: async (chunk) => {
|
|
720
|
+
assert(this._fileHandle);
|
|
721
|
+
await this._fileHandle.write(chunk.data, 0, chunk.data.byteLength, chunk.position);
|
|
722
|
+
},
|
|
723
|
+
close: async () => {
|
|
724
|
+
if (this._fileHandle) {
|
|
725
|
+
await this._fileHandle.close();
|
|
726
|
+
this._fileHandle = null;
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
this._streamTarget = new StreamTarget(writable, {
|
|
732
|
+
chunked: true,
|
|
733
|
+
...options,
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** @internal */
|
|
738
|
+
_start() {
|
|
739
|
+
this._streamTarget._start();
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/** @internal */
|
|
743
|
+
_write(data: Uint8Array, pos: number) {
|
|
744
|
+
this._streamTarget._write(data, pos);
|
|
745
|
+
this._dispatchWrite(pos, pos + data.byteLength);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/** @internal */
|
|
749
|
+
async _flush() {
|
|
750
|
+
return this._streamTarget._flush();
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/** @internal */
|
|
754
|
+
async _finalize() {
|
|
755
|
+
await this._streamTarget._finalize();
|
|
756
|
+
this._emit('finalized');
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/** @internal */
|
|
760
|
+
async _close() {
|
|
761
|
+
return this._streamTarget._close();
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/** @internal */
|
|
765
|
+
override _setMonotonicity(monotonicity: boolean): void {
|
|
766
|
+
super._setMonotonicity(monotonicity);
|
|
767
|
+
this._streamTarget._setMonotonicity(monotonicity);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* This target just discards all incoming data. It is useful for when you need an {@link Output} but extract data from
|
|
773
|
+
* it differently, for example through format-specific callbacks (`onMoof`, `onMdat`, ...) or encoder events.
|
|
774
|
+
* @group Output targets
|
|
775
|
+
* @public
|
|
776
|
+
*/
|
|
777
|
+
export class NullTarget extends Target {
|
|
778
|
+
/** @internal */
|
|
779
|
+
_start() {}
|
|
780
|
+
|
|
781
|
+
/** @internal */
|
|
782
|
+
|
|
783
|
+
_write(data: Uint8Array, pos: number) {
|
|
784
|
+
this._dispatchWrite(pos, pos + data.byteLength);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/** @internal */
|
|
788
|
+
async _flush() {}
|
|
789
|
+
|
|
790
|
+
/** @internal */
|
|
791
|
+
async _finalize() {
|
|
792
|
+
this._emit('finalized');
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/** @internal */
|
|
796
|
+
async _close() {}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* A target that writes to a subrange (defined by an offset) of another, underlying target. Useful for writing a file
|
|
801
|
+
* into a section of a larger file.
|
|
802
|
+
* @group Output targets
|
|
803
|
+
* @public
|
|
804
|
+
*/
|
|
805
|
+
export class RangedTarget extends Target {
|
|
806
|
+
/** @internal */
|
|
807
|
+
_baseTarget: Target;
|
|
808
|
+
/** @internal */
|
|
809
|
+
_offset: number;
|
|
810
|
+
|
|
811
|
+
/** @internal */
|
|
812
|
+
constructor(baseTarget: Target, offset: number) {
|
|
813
|
+
super();
|
|
814
|
+
|
|
815
|
+
this._baseTarget = baseTarget;
|
|
816
|
+
this._offset = offset;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** @internal */
|
|
820
|
+
_start() {}
|
|
821
|
+
|
|
822
|
+
/** @internal */
|
|
823
|
+
_write(data: Uint8Array, pos: number): void {
|
|
824
|
+
this._baseTarget._write(data, this._offset + pos);
|
|
825
|
+
this._dispatchWrite(pos, pos + data.byteLength);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/** @internal */
|
|
829
|
+
_flush() {
|
|
830
|
+
return this._baseTarget._flush();
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/** @internal */
|
|
834
|
+
async _finalize() {
|
|
835
|
+
this._emit('finalized');
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** @internal */
|
|
839
|
+
async _close() {}
|
|
840
|
+
|
|
841
|
+
/** @internal */
|
|
842
|
+
override _setMonotonicity(monotonicity: boolean): void {
|
|
843
|
+
super._setMonotonicity(monotonicity);
|
|
844
|
+
this._baseTarget._setMonotonicity(monotonicity);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* A special target for writing multi-file media where each file is uniquely identified by a path.
|
|
850
|
+
* @group Output targets
|
|
851
|
+
* @public
|
|
852
|
+
*/
|
|
853
|
+
export class PathedTarget<T extends Target> {
|
|
854
|
+
/** Creates a new {@link PathedTarget} from a root path and a callback. */
|
|
855
|
+
constructor(
|
|
856
|
+
/** The path that points to the root file; the entry file of the media. */
|
|
857
|
+
public readonly rootPath: FilePath,
|
|
858
|
+
/** The callback that is called for each file that needs to be written; must return a {@link Target}. */
|
|
859
|
+
public readonly getTarget: (request: TargetRequest) => MaybePromise<T>,
|
|
860
|
+
) {
|
|
861
|
+
if (typeof rootPath !== 'string') {
|
|
862
|
+
throw new TypeError('rootPath must be a string.');
|
|
863
|
+
}
|
|
864
|
+
if (typeof getTarget !== 'function') {
|
|
865
|
+
throw new TypeError('getTarget must be a function.');
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* A request for a {@link Target} at the given path.
|
|
872
|
+
* @group Output targets
|
|
873
|
+
* @public
|
|
874
|
+
*/
|
|
875
|
+
export type TargetRequest = {
|
|
876
|
+
/** The requested file path. */
|
|
877
|
+
path: FilePath;
|
|
878
|
+
/** Whether the to-be-written file will be the root file. */
|
|
879
|
+
isRoot: boolean;
|
|
880
|
+
/** The MIME type of the to-be-written file. */
|
|
881
|
+
mimeType: string;
|
|
882
|
+
};
|