@remotion/media-parser 4.0.239 → 4.0.241
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/boxes/avc/codec-private.d.ts +1 -1
- package/dist/boxes/transport-stream/adts-header.d.ts +1 -1
- package/dist/boxes/transport-stream/discard-rest-of-packet.d.ts +1 -1
- package/dist/boxes/webm/ebml.d.ts +1 -1
- package/dist/boxes/webm/make-header.d.ts +3 -3
- package/dist/buffer-iterator.d.ts +2 -6
- package/dist/buffer-iterator.js +4 -29
- package/dist/create/iso-base-media/codec-specific/avc1.d.ts +1 -1
- package/dist/create/iso-base-media/codec-specific/create-codec-specific-data.d.ts +1 -1
- package/dist/create/iso-base-media/codec-specific/mp4a.d.ts +1 -1
- package/dist/create/iso-base-media/create-colr.d.ts +1 -1
- package/dist/create/iso-base-media/create-ftyp.d.ts +2 -2
- package/dist/create/iso-base-media/create-ilst.d.ts +1 -1
- package/dist/create/iso-base-media/create-mdia.d.ts +1 -1
- package/dist/create/iso-base-media/create-moov.d.ts +1 -1
- package/dist/create/iso-base-media/create-mvhd.d.ts +1 -1
- package/dist/create/iso-base-media/create-trak.d.ts +1 -1
- package/dist/create/iso-base-media/create-udta.d.ts +1 -1
- package/dist/create/iso-base-media/create-url.d.ts +1 -1
- package/dist/create/iso-base-media/ilst/create-cmt.d.ts +1 -1
- package/dist/create/iso-base-media/ilst/create-too.d.ts +1 -1
- package/dist/create/iso-base-media/mdia/create-mdhd.d.ts +1 -1
- package/dist/create/iso-base-media/mp4-header.d.ts +1 -1
- package/dist/create/iso-base-media/primitives.d.ts +13 -13
- package/dist/create/iso-base-media/serialize-track.d.ts +1 -1
- package/dist/create/iso-base-media/trak/create-tkhd.d.ts +2 -2
- package/dist/create/iso-base-media/trak/mdia/create-minf.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-dinf.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-smhd.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-stbl.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-vmhd.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-ctts.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stco.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stsc.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stss.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stsz.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stts.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-avc1.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-avcc.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-pasp.d.ts +1 -1
- package/dist/create/iso-base-media/udta/create-meta.d.ts +1 -1
- package/dist/create/iso-base-media/udta/meta/create-hdlr.d.ts +1 -1
- package/dist/create/matroska/cluster-segment.d.ts +1 -1
- package/dist/emit-available-info.d.ts +6 -3
- package/dist/emit-available-info.js +113 -64
- package/dist/errors/detect-file-type.d.ts +1 -0
- package/dist/errors/detect-file-type.js +88 -0
- package/dist/errors/file-types.d.ts +1 -0
- package/dist/errors/file-types.js +88 -0
- package/dist/errors.d.ts +68 -0
- package/dist/errors.js +71 -0
- package/dist/esm/from-fetch.mjs +1 -0
- package/dist/esm/from-node.mjs +1 -0
- package/dist/esm/from-web-file.mjs +2 -1
- package/dist/esm/index.mjs +673 -107
- package/dist/file-types/bmp.d.ts +6 -0
- package/dist/file-types/bmp.js +23 -0
- package/dist/file-types/detect-file-type.d.ts +42 -0
- package/dist/file-types/detect-file-type.js +59 -0
- package/dist/file-types/get-jpeg-dimensions.d.ts +4 -0
- package/dist/file-types/get-jpeg-dimensions.js +32 -0
- package/dist/file-types/index.d.ts +2 -0
- package/dist/file-types/index.js +57 -0
- package/dist/file-types/jpeg.d.ts +12 -0
- package/dist/file-types/jpeg.js +44 -0
- package/dist/file-types/pdf.d.ts +4 -0
- package/dist/file-types/pdf.js +12 -0
- package/dist/file-types/png.d.ts +10 -0
- package/dist/file-types/png.js +32 -0
- package/dist/file-types/webp.d.ts +6 -0
- package/dist/file-types/webp.js +69 -0
- package/dist/file-types.d.ts +1 -0
- package/dist/file-types.js +88 -0
- package/dist/get-audio-codec.d.ts +1 -1
- package/dist/get-fields-from-callbacks.d.ts +5 -0
- package/dist/get-fields-from-callbacks.js +27 -0
- package/dist/get-location.d.ts +13 -0
- package/dist/get-location.js +40 -0
- package/dist/has-all-info.d.ts +5 -1
- package/dist/has-all-info.js +11 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -1
- package/dist/options.d.ts +40 -49
- package/dist/parse-media.js +53 -14
- package/dist/parse-video.d.ts +4 -1
- package/dist/parse-video.js +71 -8
- package/dist/probing/detect-file-type.d.ts +1 -0
- package/dist/probing/detect-file-type.js +88 -0
- package/dist/probing/get-jpeg-dimensions.d.ts +4 -0
- package/dist/probing/get-jpeg-dimensions.js +32 -0
- package/dist/readers/from-fetch.js +1 -0
- package/dist/readers/from-node.js +1 -0
- package/dist/readers/from-web-file.js +1 -0
- package/dist/readers/reader.d.ts +1 -0
- package/dist/state/can-skip-tracks.js +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -7,108 +7,122 @@ const get_dimensions_1 = require("./get-dimensions");
|
|
|
7
7
|
const get_duration_1 = require("./get-duration");
|
|
8
8
|
const get_fps_1 = require("./get-fps");
|
|
9
9
|
const get_is_hdr_1 = require("./get-is-hdr");
|
|
10
|
+
const get_location_1 = require("./get-location");
|
|
10
11
|
const get_tracks_1 = require("./get-tracks");
|
|
11
12
|
const get_video_codec_1 = require("./get-video-codec");
|
|
12
13
|
const get_metadata_1 = require("./metadata/get-metadata");
|
|
13
|
-
const emitAvailableInfo = ({ hasInfo, parseResult,
|
|
14
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
14
|
+
const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue, contentLength, name, mimeType, fieldsInReturnValue, emittedFields, }) => {
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
15
16
|
const keys = Object.keys(hasInfo);
|
|
16
17
|
for (const key of keys) {
|
|
17
18
|
if (key === 'structure') {
|
|
18
|
-
if (parseResult &&
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if (parseResult && hasInfo.structure && !emittedFields.structure) {
|
|
20
|
+
(_a = callbacks.onStructure) === null || _a === void 0 ? void 0 : _a.call(callbacks, parseResult.segments);
|
|
21
|
+
if (fieldsInReturnValue.structure) {
|
|
22
|
+
returnValue.structure = parseResult.segments;
|
|
23
|
+
}
|
|
24
|
+
emittedFields.structure = true;
|
|
23
25
|
}
|
|
24
26
|
continue;
|
|
25
27
|
}
|
|
26
28
|
if (key === 'durationInSeconds') {
|
|
27
29
|
if (hasInfo.durationInSeconds &&
|
|
28
|
-
|
|
30
|
+
!emittedFields.durationInSeconds &&
|
|
29
31
|
parseResult) {
|
|
30
32
|
const durationInSeconds = (0, get_duration_1.getDuration)(parseResult.segments, state);
|
|
31
|
-
(_b =
|
|
32
|
-
|
|
33
|
+
(_b = callbacks.onDurationInSeconds) === null || _b === void 0 ? void 0 : _b.call(callbacks, durationInSeconds);
|
|
34
|
+
if (fieldsInReturnValue.durationInSeconds) {
|
|
35
|
+
returnValue.durationInSeconds = durationInSeconds;
|
|
36
|
+
}
|
|
37
|
+
emittedFields.durationInSeconds = true;
|
|
33
38
|
}
|
|
34
39
|
continue;
|
|
35
40
|
}
|
|
36
41
|
if (key === 'dimensions') {
|
|
37
|
-
if (hasInfo.dimensions &&
|
|
38
|
-
returnValue.dimensions === undefined &&
|
|
39
|
-
parseResult) {
|
|
42
|
+
if (hasInfo.dimensions && !emittedFields.dimensions && parseResult) {
|
|
40
43
|
const dimensionsQueried = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
41
44
|
const dimensions = {
|
|
42
45
|
height: dimensionsQueried.height,
|
|
43
46
|
width: dimensionsQueried.width,
|
|
44
47
|
};
|
|
45
|
-
(_c =
|
|
46
|
-
|
|
48
|
+
(_c = callbacks.onDimensions) === null || _c === void 0 ? void 0 : _c.call(callbacks, dimensions);
|
|
49
|
+
if (fieldsInReturnValue.dimensions) {
|
|
50
|
+
returnValue.dimensions = dimensions;
|
|
51
|
+
}
|
|
52
|
+
emittedFields.dimensions = true;
|
|
47
53
|
}
|
|
48
54
|
continue;
|
|
49
55
|
}
|
|
50
56
|
if (key === 'unrotatedDimensions') {
|
|
51
|
-
if (
|
|
52
|
-
|
|
57
|
+
if (hasInfo.unrotatedDimensions &&
|
|
58
|
+
!emittedFields.unrotatedDimensions &&
|
|
53
59
|
parseResult) {
|
|
54
60
|
const dimensionsQueried = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
55
61
|
const unrotatedDimensions = {
|
|
56
62
|
height: dimensionsQueried.unrotatedHeight,
|
|
57
63
|
width: dimensionsQueried.unrotatedWidth,
|
|
58
64
|
};
|
|
59
|
-
(_d =
|
|
60
|
-
|
|
65
|
+
(_d = callbacks.onUnrotatedDimensions) === null || _d === void 0 ? void 0 : _d.call(callbacks, unrotatedDimensions);
|
|
66
|
+
if (fieldsInReturnValue.unrotatedDimensions) {
|
|
67
|
+
returnValue.unrotatedDimensions = unrotatedDimensions;
|
|
68
|
+
}
|
|
69
|
+
emittedFields.unrotatedDimensions = true;
|
|
61
70
|
}
|
|
62
71
|
continue;
|
|
63
72
|
}
|
|
64
73
|
if (key === 'rotation') {
|
|
65
|
-
if (
|
|
66
|
-
hasInfo.rotation &&
|
|
67
|
-
parseResult) {
|
|
74
|
+
if (hasInfo.rotation && !emittedFields.rotation && parseResult) {
|
|
68
75
|
const dimensionsQueried = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
69
76
|
const { rotation } = dimensionsQueried;
|
|
70
|
-
(_e =
|
|
71
|
-
|
|
77
|
+
(_e = callbacks.onRotation) === null || _e === void 0 ? void 0 : _e.call(callbacks, rotation);
|
|
78
|
+
if (fieldsInReturnValue.rotation) {
|
|
79
|
+
returnValue.rotation = rotation;
|
|
80
|
+
}
|
|
81
|
+
emittedFields.rotation = true;
|
|
72
82
|
}
|
|
73
83
|
continue;
|
|
74
84
|
}
|
|
75
85
|
if (key === 'fps') {
|
|
76
|
-
if (
|
|
86
|
+
if (!emittedFields.fps && hasInfo.fps && parseResult) {
|
|
77
87
|
const fps = (0, get_fps_1.getFps)(parseResult.segments);
|
|
78
|
-
(_f =
|
|
79
|
-
|
|
88
|
+
(_f = callbacks.onFps) === null || _f === void 0 ? void 0 : _f.call(callbacks, fps);
|
|
89
|
+
if (fieldsInReturnValue.fps) {
|
|
90
|
+
returnValue.fps = fps;
|
|
91
|
+
}
|
|
92
|
+
emittedFields.fps = true;
|
|
80
93
|
}
|
|
81
94
|
continue;
|
|
82
95
|
}
|
|
83
96
|
if (key === 'videoCodec') {
|
|
84
|
-
if (
|
|
85
|
-
hasInfo.videoCodec &&
|
|
86
|
-
parseResult) {
|
|
97
|
+
if (!emittedFields.videoCodec && hasInfo.videoCodec && parseResult) {
|
|
87
98
|
const videoCodec = (0, get_video_codec_1.getVideoCodec)(parseResult.segments, state);
|
|
88
|
-
(_g =
|
|
89
|
-
|
|
99
|
+
(_g = callbacks.onVideoCodec) === null || _g === void 0 ? void 0 : _g.call(callbacks, videoCodec);
|
|
100
|
+
if (fieldsInReturnValue.videoCodec) {
|
|
101
|
+
returnValue.videoCodec = videoCodec;
|
|
102
|
+
}
|
|
103
|
+
emittedFields.videoCodec = true;
|
|
90
104
|
}
|
|
91
105
|
continue;
|
|
92
106
|
}
|
|
93
107
|
if (key === 'audioCodec') {
|
|
94
|
-
if (
|
|
95
|
-
hasInfo.audioCodec &&
|
|
96
|
-
parseResult) {
|
|
108
|
+
if (!emittedFields.audioCodec && hasInfo.audioCodec && parseResult) {
|
|
97
109
|
const audioCodec = (0, get_audio_codec_1.getAudioCodec)(parseResult.segments, state);
|
|
98
|
-
(_h =
|
|
99
|
-
|
|
110
|
+
(_h = callbacks.onAudioCodec) === null || _h === void 0 ? void 0 : _h.call(callbacks, audioCodec);
|
|
111
|
+
if (fieldsInReturnValue.audioCodec) {
|
|
112
|
+
returnValue.audioCodec = audioCodec;
|
|
113
|
+
}
|
|
114
|
+
emittedFields.audioCodec = true;
|
|
100
115
|
}
|
|
101
116
|
continue;
|
|
102
117
|
}
|
|
103
118
|
if (key === 'tracks') {
|
|
104
|
-
if (hasInfo.tracks &&
|
|
105
|
-
returnValue.videoTracks === undefined &&
|
|
106
|
-
returnValue.audioTracks === undefined &&
|
|
107
|
-
parseResult) {
|
|
119
|
+
if (!emittedFields.tracks && hasInfo.tracks && parseResult) {
|
|
108
120
|
const { videoTracks, audioTracks } = (0, get_tracks_1.getTracks)(parseResult.segments, state);
|
|
109
|
-
(_j =
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
(_j = callbacks.onTracks) === null || _j === void 0 ? void 0 : _j.call(callbacks, { videoTracks, audioTracks });
|
|
122
|
+
if (fieldsInReturnValue.tracks) {
|
|
123
|
+
returnValue.tracks = { videoTracks, audioTracks };
|
|
124
|
+
}
|
|
125
|
+
emittedFields.tracks = true;
|
|
112
126
|
}
|
|
113
127
|
continue;
|
|
114
128
|
}
|
|
@@ -116,49 +130,84 @@ const emitAvailableInfo = ({ hasInfo, parseResult, moreFields, state, returnValu
|
|
|
116
130
|
// Special case: Always emitting internal stats at the end
|
|
117
131
|
if (hasInfo.internalStats) {
|
|
118
132
|
const internalStats = state.getInternalStats();
|
|
119
|
-
|
|
133
|
+
if (fieldsInReturnValue.internalStats) {
|
|
134
|
+
returnValue.internalStats = internalStats;
|
|
135
|
+
}
|
|
136
|
+
emittedFields.internalStats = true;
|
|
120
137
|
}
|
|
121
138
|
continue;
|
|
122
139
|
}
|
|
123
140
|
if (key === 'size') {
|
|
124
|
-
if (
|
|
125
|
-
(_k =
|
|
126
|
-
|
|
141
|
+
if (!emittedFields.size && hasInfo.size) {
|
|
142
|
+
(_k = callbacks.onSize) === null || _k === void 0 ? void 0 : _k.call(callbacks, contentLength);
|
|
143
|
+
if (fieldsInReturnValue.size) {
|
|
144
|
+
returnValue.size = contentLength;
|
|
145
|
+
}
|
|
146
|
+
emittedFields.size = true;
|
|
147
|
+
}
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (key === 'mimeType') {
|
|
151
|
+
if (!emittedFields.mimeType && hasInfo.mimeType) {
|
|
152
|
+
(_l = callbacks.onMimeType) === null || _l === void 0 ? void 0 : _l.call(callbacks, mimeType);
|
|
153
|
+
if (fieldsInReturnValue.mimeType) {
|
|
154
|
+
returnValue.mimeType = mimeType;
|
|
155
|
+
}
|
|
156
|
+
emittedFields.mimeType = true;
|
|
127
157
|
}
|
|
128
158
|
continue;
|
|
129
159
|
}
|
|
130
160
|
if (key === 'name') {
|
|
131
|
-
if (
|
|
132
|
-
(
|
|
133
|
-
|
|
161
|
+
if (!emittedFields.name && hasInfo.name) {
|
|
162
|
+
(_m = callbacks.onName) === null || _m === void 0 ? void 0 : _m.call(callbacks, name);
|
|
163
|
+
if (fieldsInReturnValue.name) {
|
|
164
|
+
returnValue.name = name;
|
|
165
|
+
}
|
|
166
|
+
emittedFields.name = true;
|
|
134
167
|
}
|
|
135
168
|
continue;
|
|
136
169
|
}
|
|
137
170
|
if (key === 'isHdr') {
|
|
138
|
-
if (returnValue.isHdr
|
|
171
|
+
if (!returnValue.isHdr && hasInfo.isHdr && parseResult) {
|
|
139
172
|
const isHdr = (0, get_is_hdr_1.getIsHdr)(parseResult.segments, state);
|
|
140
|
-
(
|
|
141
|
-
|
|
173
|
+
(_o = callbacks.onIsHdr) === null || _o === void 0 ? void 0 : _o.call(callbacks, isHdr);
|
|
174
|
+
if (fieldsInReturnValue.isHdr) {
|
|
175
|
+
returnValue.isHdr = isHdr;
|
|
176
|
+
}
|
|
177
|
+
emittedFields.isHdr = true;
|
|
142
178
|
}
|
|
143
179
|
continue;
|
|
144
180
|
}
|
|
145
181
|
if (key === 'container') {
|
|
146
|
-
if (returnValue.container
|
|
147
|
-
hasInfo.container &&
|
|
148
|
-
parseResult) {
|
|
182
|
+
if (!returnValue.container && hasInfo.container && parseResult) {
|
|
149
183
|
const container = (0, get_container_1.getContainer)(parseResult.segments);
|
|
150
|
-
(
|
|
151
|
-
|
|
184
|
+
(_p = callbacks.onContainer) === null || _p === void 0 ? void 0 : _p.call(callbacks, container);
|
|
185
|
+
if (fieldsInReturnValue.container) {
|
|
186
|
+
returnValue.container = container;
|
|
187
|
+
}
|
|
188
|
+
emittedFields.container = true;
|
|
152
189
|
}
|
|
153
190
|
continue;
|
|
154
191
|
}
|
|
155
192
|
if (key === 'metadata') {
|
|
156
|
-
if (
|
|
157
|
-
hasInfo.metadata &&
|
|
158
|
-
parseResult) {
|
|
193
|
+
if (!emittedFields.metadata && hasInfo.metadata && parseResult) {
|
|
159
194
|
const metadata = (0, get_metadata_1.getMetadata)(parseResult.segments);
|
|
160
|
-
(
|
|
161
|
-
|
|
195
|
+
(_q = callbacks.onMetadata) === null || _q === void 0 ? void 0 : _q.call(callbacks, metadata);
|
|
196
|
+
if (fieldsInReturnValue.metadata) {
|
|
197
|
+
returnValue.metadata = metadata;
|
|
198
|
+
}
|
|
199
|
+
emittedFields.metadata = true;
|
|
200
|
+
}
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (key === 'location') {
|
|
204
|
+
if (!emittedFields.location && hasInfo.location && parseResult) {
|
|
205
|
+
const location = (0, get_location_1.getLocation)(parseResult.segments);
|
|
206
|
+
(_r = callbacks.onLocation) === null || _r === void 0 ? void 0 : _r.call(callbacks, location);
|
|
207
|
+
if (fieldsInReturnValue.location) {
|
|
208
|
+
returnValue.location = location;
|
|
209
|
+
}
|
|
210
|
+
emittedFields.location = true;
|
|
162
211
|
}
|
|
163
212
|
continue;
|
|
164
213
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const detectFileType: (data: Uint8Array) => "webp" | "riff" | "webm" | "iso-base-media" | "transport-stream" | "mp3" | "gif" | "png" | "bmp" | "jpeg" | "unknown";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectFileType = void 0;
|
|
4
|
+
const make_header_1 = require("../boxes/webm/make-header");
|
|
5
|
+
const matchesPattern = (pattern) => {
|
|
6
|
+
return (data) => {
|
|
7
|
+
return pattern.every((value, index) => data[index] === value);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const isRiff = (data) => {
|
|
11
|
+
const riffPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
12
|
+
return matchesPattern(riffPattern)(data.subarray(0, 4));
|
|
13
|
+
};
|
|
14
|
+
const isWebm = (data) => {
|
|
15
|
+
return matchesPattern(make_header_1.webmPattern)(data.subarray(0, 4));
|
|
16
|
+
};
|
|
17
|
+
const isIsoBaseMedia = (data) => {
|
|
18
|
+
const isoBaseMediaMp4Pattern = new TextEncoder().encode('ftyp');
|
|
19
|
+
return matchesPattern(isoBaseMediaMp4Pattern)(data.subarray(4, 8));
|
|
20
|
+
};
|
|
21
|
+
const isTransportStream = (data) => {
|
|
22
|
+
return data[0] === 0x47 && data[188] === 0x47;
|
|
23
|
+
};
|
|
24
|
+
const isMp3 = (data) => {
|
|
25
|
+
const mpegPattern = new Uint8Array([0xff, 0xf3, 0xe4, 0x64]);
|
|
26
|
+
return matchesPattern(mpegPattern)(data.subarray(0, 4));
|
|
27
|
+
};
|
|
28
|
+
const isGif = (data) => {
|
|
29
|
+
const gifPattern = new Uint8Array([0x47, 0x49, 0x46, 0x38]);
|
|
30
|
+
return matchesPattern(gifPattern)(data.subarray(0, 4));
|
|
31
|
+
};
|
|
32
|
+
const isPng = (data) => {
|
|
33
|
+
const pngPattern = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
34
|
+
return matchesPattern(pngPattern)(data.subarray(0, 4));
|
|
35
|
+
};
|
|
36
|
+
const isBmp = (data) => {
|
|
37
|
+
const bmpPattern = new Uint8Array([0x42, 0x4d]);
|
|
38
|
+
return matchesPattern(bmpPattern)(data.subarray(0, 2));
|
|
39
|
+
};
|
|
40
|
+
const isJpeg = (data) => {
|
|
41
|
+
const jpegPattern = new Uint8Array([0xff, 0xd8]);
|
|
42
|
+
const jpeg = matchesPattern(jpegPattern)(data.subarray(0, 2));
|
|
43
|
+
if (!jpeg) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const width = data[6] * 256 + data[7];
|
|
47
|
+
const height = data[8] * 256 + data[9];
|
|
48
|
+
console.log(width, height);
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
const isWebp = (data) => {
|
|
52
|
+
const webpPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
53
|
+
return matchesPattern(webpPattern)(data.subarray(0, 4));
|
|
54
|
+
};
|
|
55
|
+
const detectFileType = (data) => {
|
|
56
|
+
if (isWebp(data)) {
|
|
57
|
+
return 'webp';
|
|
58
|
+
}
|
|
59
|
+
if (isRiff(data)) {
|
|
60
|
+
return 'riff';
|
|
61
|
+
}
|
|
62
|
+
if (isWebm(data)) {
|
|
63
|
+
return 'webm';
|
|
64
|
+
}
|
|
65
|
+
if (isIsoBaseMedia(data)) {
|
|
66
|
+
return 'iso-base-media';
|
|
67
|
+
}
|
|
68
|
+
if (isTransportStream(data)) {
|
|
69
|
+
return 'transport-stream';
|
|
70
|
+
}
|
|
71
|
+
if (isMp3(data)) {
|
|
72
|
+
return 'mp3';
|
|
73
|
+
}
|
|
74
|
+
if (isGif(data)) {
|
|
75
|
+
return 'gif';
|
|
76
|
+
}
|
|
77
|
+
if (isPng(data)) {
|
|
78
|
+
return 'png';
|
|
79
|
+
}
|
|
80
|
+
if (isBmp(data)) {
|
|
81
|
+
return 'bmp';
|
|
82
|
+
}
|
|
83
|
+
if (isJpeg(data)) {
|
|
84
|
+
return 'jpeg';
|
|
85
|
+
}
|
|
86
|
+
return 'unknown';
|
|
87
|
+
};
|
|
88
|
+
exports.detectFileType = detectFileType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const detectFileType: (data: Uint8Array) => "mp3" | "unknown" | "webm" | "transport-stream" | "iso-base-media" | "riff" | "gif" | "bmp" | "jpeg" | "png" | "webp";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectFileType = void 0;
|
|
4
|
+
const make_header_1 = require("./boxes/webm/make-header");
|
|
5
|
+
const matchesPattern = (pattern) => {
|
|
6
|
+
return (data) => {
|
|
7
|
+
return pattern.every((value, index) => data[index] === value);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const isRiff = (data) => {
|
|
11
|
+
const riffPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
12
|
+
return matchesPattern(riffPattern)(data.subarray(0, 4));
|
|
13
|
+
};
|
|
14
|
+
const isWebm = (data) => {
|
|
15
|
+
return matchesPattern(make_header_1.webmPattern)(data.subarray(0, 4));
|
|
16
|
+
};
|
|
17
|
+
const isIsoBaseMedia = (data) => {
|
|
18
|
+
const isoBaseMediaMp4Pattern = new TextEncoder().encode('ftyp');
|
|
19
|
+
return matchesPattern(isoBaseMediaMp4Pattern)(data.subarray(4, 8));
|
|
20
|
+
};
|
|
21
|
+
const isTransportStream = (data) => {
|
|
22
|
+
return data[0] === 0x47 && data[188] === 0x47;
|
|
23
|
+
};
|
|
24
|
+
const isMp3 = (data) => {
|
|
25
|
+
const mpegPattern = new Uint8Array([0xff, 0xf3, 0xe4, 0x64]);
|
|
26
|
+
return matchesPattern(mpegPattern)(data.subarray(0, 4));
|
|
27
|
+
};
|
|
28
|
+
const isGif = (data) => {
|
|
29
|
+
const gifPattern = new Uint8Array([0x47, 0x49, 0x46, 0x38]);
|
|
30
|
+
return matchesPattern(gifPattern)(data.subarray(0, 4));
|
|
31
|
+
};
|
|
32
|
+
const isPng = (data) => {
|
|
33
|
+
const pngPattern = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
34
|
+
return matchesPattern(pngPattern)(data.subarray(0, 4));
|
|
35
|
+
};
|
|
36
|
+
const isBmp = (data) => {
|
|
37
|
+
const bmpPattern = new Uint8Array([0x42, 0x4d]);
|
|
38
|
+
return matchesPattern(bmpPattern)(data.subarray(0, 2));
|
|
39
|
+
};
|
|
40
|
+
const isJpeg = (data) => {
|
|
41
|
+
const jpegPattern = new Uint8Array([0xff, 0xd8]);
|
|
42
|
+
const jpeg = matchesPattern(jpegPattern)(data.subarray(0, 2));
|
|
43
|
+
if (!jpeg) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const width = data[6] * 256 + data[7];
|
|
47
|
+
const height = data[8] * 256 + data[9];
|
|
48
|
+
console.log(width, height);
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
const isWebp = (data) => {
|
|
52
|
+
const webpPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
53
|
+
return matchesPattern(webpPattern)(data.subarray(0, 4));
|
|
54
|
+
};
|
|
55
|
+
const detectFileType = (data) => {
|
|
56
|
+
if (isWebp(data)) {
|
|
57
|
+
return 'webp';
|
|
58
|
+
}
|
|
59
|
+
if (isRiff(data)) {
|
|
60
|
+
return 'riff';
|
|
61
|
+
}
|
|
62
|
+
if (isWebm(data)) {
|
|
63
|
+
return 'webm';
|
|
64
|
+
}
|
|
65
|
+
if (isIsoBaseMedia(data)) {
|
|
66
|
+
return 'iso-base-media';
|
|
67
|
+
}
|
|
68
|
+
if (isTransportStream(data)) {
|
|
69
|
+
return 'transport-stream';
|
|
70
|
+
}
|
|
71
|
+
if (isMp3(data)) {
|
|
72
|
+
return 'mp3';
|
|
73
|
+
}
|
|
74
|
+
if (isGif(data)) {
|
|
75
|
+
return 'gif';
|
|
76
|
+
}
|
|
77
|
+
if (isPng(data)) {
|
|
78
|
+
return 'png';
|
|
79
|
+
}
|
|
80
|
+
if (isBmp(data)) {
|
|
81
|
+
return 'bmp';
|
|
82
|
+
}
|
|
83
|
+
if (isJpeg(data)) {
|
|
84
|
+
return 'jpeg';
|
|
85
|
+
}
|
|
86
|
+
return 'unknown';
|
|
87
|
+
};
|
|
88
|
+
exports.detectFileType = detectFileType;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export declare class IsAGifError extends Error {
|
|
2
|
+
mimeType: string | null;
|
|
3
|
+
sizeInBytes: number | null;
|
|
4
|
+
fileName: string | null;
|
|
5
|
+
constructor({ message, mimeType, sizeInBytes, fileName, }: {
|
|
6
|
+
message: string;
|
|
7
|
+
mimeType: string | null;
|
|
8
|
+
sizeInBytes: number | null;
|
|
9
|
+
fileName: string | null;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
type ImageType = 'png' | 'jpeg' | 'bmp' | 'webp';
|
|
13
|
+
type Dimensions = {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
};
|
|
17
|
+
export declare class IsAnImageError extends Error {
|
|
18
|
+
imageType: ImageType;
|
|
19
|
+
dimensions: Dimensions | null;
|
|
20
|
+
mimeType: string | null;
|
|
21
|
+
sizeInBytes: number | null;
|
|
22
|
+
fileName: string | null;
|
|
23
|
+
constructor({ dimensions, imageType, message, mimeType, sizeInBytes, fileName, }: {
|
|
24
|
+
message: string;
|
|
25
|
+
imageType: ImageType;
|
|
26
|
+
dimensions: Dimensions | null;
|
|
27
|
+
mimeType: string | null;
|
|
28
|
+
sizeInBytes: number | null;
|
|
29
|
+
fileName: string | null;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export declare class IsAPdfError extends Error {
|
|
33
|
+
mimeType: string | null;
|
|
34
|
+
sizeInBytes: number | null;
|
|
35
|
+
fileName: string | null;
|
|
36
|
+
constructor({ message, mimeType, sizeInBytes, fileName, }: {
|
|
37
|
+
message: string;
|
|
38
|
+
mimeType: string | null;
|
|
39
|
+
sizeInBytes: number | null;
|
|
40
|
+
fileName: string | null;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export declare class IsAnUnsupportedFileTypeError extends Error {
|
|
44
|
+
mimeType: string | null;
|
|
45
|
+
sizeInBytes: number | null;
|
|
46
|
+
fileName: string | null;
|
|
47
|
+
constructor({ message, mimeType, sizeInBytes, fileName, }: {
|
|
48
|
+
message: string;
|
|
49
|
+
mimeType: string | null;
|
|
50
|
+
sizeInBytes: number | null;
|
|
51
|
+
fileName: string | null;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
type UnsupportedAudioType = 'mp3' | 'wav' | 'aac';
|
|
55
|
+
export declare class IsAnUnsupportedAudioTypeError extends Error {
|
|
56
|
+
mimeType: string | null;
|
|
57
|
+
sizeInBytes: number | null;
|
|
58
|
+
fileName: string | null;
|
|
59
|
+
audioType: UnsupportedAudioType | null;
|
|
60
|
+
constructor({ message, mimeType, sizeInBytes, fileName, audioType, }: {
|
|
61
|
+
message: string;
|
|
62
|
+
mimeType: string | null;
|
|
63
|
+
sizeInBytes: number | null;
|
|
64
|
+
fileName: string | null;
|
|
65
|
+
audioType: UnsupportedAudioType | null;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export {};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsAnUnsupportedAudioTypeError = exports.IsAnUnsupportedFileTypeError = exports.IsAPdfError = exports.IsAnImageError = exports.IsAGifError = void 0;
|
|
4
|
+
class IsAGifError extends Error {
|
|
5
|
+
constructor({ message, mimeType, sizeInBytes, fileName, }) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.fileName = 'IsAGifError';
|
|
8
|
+
this.mimeType = mimeType;
|
|
9
|
+
this.sizeInBytes = sizeInBytes;
|
|
10
|
+
this.fileName = fileName;
|
|
11
|
+
if (Error.captureStackTrace) {
|
|
12
|
+
Error.captureStackTrace(this, IsAGifError);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.IsAGifError = IsAGifError;
|
|
17
|
+
class IsAnImageError extends Error {
|
|
18
|
+
constructor({ dimensions, imageType, message, mimeType, sizeInBytes, fileName, }) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'IsAnImageError';
|
|
21
|
+
this.imageType = imageType;
|
|
22
|
+
this.dimensions = dimensions;
|
|
23
|
+
this.mimeType = mimeType;
|
|
24
|
+
this.sizeInBytes = sizeInBytes;
|
|
25
|
+
this.fileName = fileName;
|
|
26
|
+
if (Error.captureStackTrace) {
|
|
27
|
+
Error.captureStackTrace(this, IsAnImageError);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.IsAnImageError = IsAnImageError;
|
|
32
|
+
class IsAPdfError extends Error {
|
|
33
|
+
constructor({ message, mimeType, sizeInBytes, fileName, }) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'IsAPdfError';
|
|
36
|
+
this.mimeType = mimeType;
|
|
37
|
+
this.sizeInBytes = sizeInBytes;
|
|
38
|
+
this.fileName = fileName;
|
|
39
|
+
if (Error.captureStackTrace) {
|
|
40
|
+
Error.captureStackTrace(this, IsAPdfError);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.IsAPdfError = IsAPdfError;
|
|
45
|
+
class IsAnUnsupportedFileTypeError extends Error {
|
|
46
|
+
constructor({ message, mimeType, sizeInBytes, fileName, }) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = 'IsAnUnsupportedFileTypeError';
|
|
49
|
+
this.mimeType = mimeType;
|
|
50
|
+
this.sizeInBytes = sizeInBytes;
|
|
51
|
+
this.fileName = fileName;
|
|
52
|
+
if (Error.captureStackTrace) {
|
|
53
|
+
Error.captureStackTrace(this, IsAnUnsupportedFileTypeError);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.IsAnUnsupportedFileTypeError = IsAnUnsupportedFileTypeError;
|
|
58
|
+
class IsAnUnsupportedAudioTypeError extends Error {
|
|
59
|
+
constructor({ message, mimeType, sizeInBytes, fileName, audioType, }) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = 'IsAnUnsupportedAudioTypeError';
|
|
62
|
+
this.mimeType = mimeType;
|
|
63
|
+
this.sizeInBytes = sizeInBytes;
|
|
64
|
+
this.fileName = fileName;
|
|
65
|
+
this.audioType = audioType;
|
|
66
|
+
if (Error.captureStackTrace) {
|
|
67
|
+
Error.captureStackTrace(this, IsAnUnsupportedAudioTypeError);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.IsAnUnsupportedAudioTypeError = IsAnUnsupportedAudioTypeError;
|
package/dist/esm/from-fetch.mjs
CHANGED
package/dist/esm/from-node.mjs
CHANGED