@remotion/media-parser 4.0.240 → 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 +107 -69
- 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 +633 -109
- 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/has-all-info.d.ts +5 -1
- package/dist/has-all-info.js +10 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -1
- package/dist/options.d.ts +36 -53
- 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 +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -11,105 +11,118 @@ const get_location_1 = require("./get-location");
|
|
|
11
11
|
const get_tracks_1 = require("./get-tracks");
|
|
12
12
|
const get_video_codec_1 = require("./get-video-codec");
|
|
13
13
|
const get_metadata_1 = require("./metadata/get-metadata");
|
|
14
|
-
const emitAvailableInfo = ({ hasInfo, parseResult,
|
|
15
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
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;
|
|
16
16
|
const keys = Object.keys(hasInfo);
|
|
17
17
|
for (const key of keys) {
|
|
18
18
|
if (key === 'structure') {
|
|
19
|
-
if (parseResult &&
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
24
25
|
}
|
|
25
26
|
continue;
|
|
26
27
|
}
|
|
27
28
|
if (key === 'durationInSeconds') {
|
|
28
29
|
if (hasInfo.durationInSeconds &&
|
|
29
|
-
|
|
30
|
+
!emittedFields.durationInSeconds &&
|
|
30
31
|
parseResult) {
|
|
31
32
|
const durationInSeconds = (0, get_duration_1.getDuration)(parseResult.segments, state);
|
|
32
|
-
(_b =
|
|
33
|
-
|
|
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;
|
|
34
38
|
}
|
|
35
39
|
continue;
|
|
36
40
|
}
|
|
37
41
|
if (key === 'dimensions') {
|
|
38
|
-
if (hasInfo.dimensions &&
|
|
39
|
-
returnValue.dimensions === undefined &&
|
|
40
|
-
parseResult) {
|
|
42
|
+
if (hasInfo.dimensions && !emittedFields.dimensions && parseResult) {
|
|
41
43
|
const dimensionsQueried = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
42
44
|
const dimensions = {
|
|
43
45
|
height: dimensionsQueried.height,
|
|
44
46
|
width: dimensionsQueried.width,
|
|
45
47
|
};
|
|
46
|
-
(_c =
|
|
47
|
-
|
|
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;
|
|
48
53
|
}
|
|
49
54
|
continue;
|
|
50
55
|
}
|
|
51
56
|
if (key === 'unrotatedDimensions') {
|
|
52
|
-
if (
|
|
53
|
-
|
|
57
|
+
if (hasInfo.unrotatedDimensions &&
|
|
58
|
+
!emittedFields.unrotatedDimensions &&
|
|
54
59
|
parseResult) {
|
|
55
60
|
const dimensionsQueried = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
56
61
|
const unrotatedDimensions = {
|
|
57
62
|
height: dimensionsQueried.unrotatedHeight,
|
|
58
63
|
width: dimensionsQueried.unrotatedWidth,
|
|
59
64
|
};
|
|
60
|
-
(_d =
|
|
61
|
-
|
|
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;
|
|
62
70
|
}
|
|
63
71
|
continue;
|
|
64
72
|
}
|
|
65
73
|
if (key === 'rotation') {
|
|
66
|
-
if (
|
|
67
|
-
hasInfo.rotation &&
|
|
68
|
-
parseResult) {
|
|
74
|
+
if (hasInfo.rotation && !emittedFields.rotation && parseResult) {
|
|
69
75
|
const dimensionsQueried = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
70
76
|
const { rotation } = dimensionsQueried;
|
|
71
|
-
(_e =
|
|
72
|
-
|
|
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;
|
|
73
82
|
}
|
|
74
83
|
continue;
|
|
75
84
|
}
|
|
76
85
|
if (key === 'fps') {
|
|
77
|
-
if (
|
|
86
|
+
if (!emittedFields.fps && hasInfo.fps && parseResult) {
|
|
78
87
|
const fps = (0, get_fps_1.getFps)(parseResult.segments);
|
|
79
|
-
(_f =
|
|
80
|
-
|
|
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;
|
|
81
93
|
}
|
|
82
94
|
continue;
|
|
83
95
|
}
|
|
84
96
|
if (key === 'videoCodec') {
|
|
85
|
-
if (
|
|
86
|
-
hasInfo.videoCodec &&
|
|
87
|
-
parseResult) {
|
|
97
|
+
if (!emittedFields.videoCodec && hasInfo.videoCodec && parseResult) {
|
|
88
98
|
const videoCodec = (0, get_video_codec_1.getVideoCodec)(parseResult.segments, state);
|
|
89
|
-
(_g =
|
|
90
|
-
|
|
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;
|
|
91
104
|
}
|
|
92
105
|
continue;
|
|
93
106
|
}
|
|
94
107
|
if (key === 'audioCodec') {
|
|
95
|
-
if (
|
|
96
|
-
hasInfo.audioCodec &&
|
|
97
|
-
parseResult) {
|
|
108
|
+
if (!emittedFields.audioCodec && hasInfo.audioCodec && parseResult) {
|
|
98
109
|
const audioCodec = (0, get_audio_codec_1.getAudioCodec)(parseResult.segments, state);
|
|
99
|
-
(_h =
|
|
100
|
-
|
|
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;
|
|
101
115
|
}
|
|
102
116
|
continue;
|
|
103
117
|
}
|
|
104
118
|
if (key === 'tracks') {
|
|
105
|
-
if (hasInfo.tracks &&
|
|
106
|
-
returnValue.videoTracks === undefined &&
|
|
107
|
-
returnValue.audioTracks === undefined &&
|
|
108
|
-
parseResult) {
|
|
119
|
+
if (!emittedFields.tracks && hasInfo.tracks && parseResult) {
|
|
109
120
|
const { videoTracks, audioTracks } = (0, get_tracks_1.getTracks)(parseResult.segments, state);
|
|
110
|
-
(_j =
|
|
111
|
-
|
|
112
|
-
|
|
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;
|
|
113
126
|
}
|
|
114
127
|
continue;
|
|
115
128
|
}
|
|
@@ -117,59 +130,84 @@ const emitAvailableInfo = ({ hasInfo, parseResult, moreFields, state, returnValu
|
|
|
117
130
|
// Special case: Always emitting internal stats at the end
|
|
118
131
|
if (hasInfo.internalStats) {
|
|
119
132
|
const internalStats = state.getInternalStats();
|
|
120
|
-
|
|
133
|
+
if (fieldsInReturnValue.internalStats) {
|
|
134
|
+
returnValue.internalStats = internalStats;
|
|
135
|
+
}
|
|
136
|
+
emittedFields.internalStats = true;
|
|
121
137
|
}
|
|
122
138
|
continue;
|
|
123
139
|
}
|
|
124
140
|
if (key === 'size') {
|
|
125
|
-
if (
|
|
126
|
-
(_k =
|
|
127
|
-
|
|
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;
|
|
128
157
|
}
|
|
129
158
|
continue;
|
|
130
159
|
}
|
|
131
160
|
if (key === 'name') {
|
|
132
|
-
if (
|
|
133
|
-
(
|
|
134
|
-
|
|
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;
|
|
135
167
|
}
|
|
136
168
|
continue;
|
|
137
169
|
}
|
|
138
170
|
if (key === 'isHdr') {
|
|
139
|
-
if (returnValue.isHdr
|
|
171
|
+
if (!returnValue.isHdr && hasInfo.isHdr && parseResult) {
|
|
140
172
|
const isHdr = (0, get_is_hdr_1.getIsHdr)(parseResult.segments, state);
|
|
141
|
-
(
|
|
142
|
-
|
|
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;
|
|
143
178
|
}
|
|
144
179
|
continue;
|
|
145
180
|
}
|
|
146
181
|
if (key === 'container') {
|
|
147
|
-
if (returnValue.container
|
|
148
|
-
hasInfo.container &&
|
|
149
|
-
parseResult) {
|
|
182
|
+
if (!returnValue.container && hasInfo.container && parseResult) {
|
|
150
183
|
const container = (0, get_container_1.getContainer)(parseResult.segments);
|
|
151
|
-
(
|
|
152
|
-
|
|
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;
|
|
153
189
|
}
|
|
154
190
|
continue;
|
|
155
191
|
}
|
|
156
192
|
if (key === 'metadata') {
|
|
157
|
-
if (
|
|
158
|
-
hasInfo.metadata &&
|
|
159
|
-
parseResult) {
|
|
193
|
+
if (!emittedFields.metadata && hasInfo.metadata && parseResult) {
|
|
160
194
|
const metadata = (0, get_metadata_1.getMetadata)(parseResult.segments);
|
|
161
|
-
(
|
|
162
|
-
|
|
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;
|
|
163
200
|
}
|
|
164
201
|
continue;
|
|
165
202
|
}
|
|
166
203
|
if (key === 'location') {
|
|
167
|
-
if (
|
|
168
|
-
hasInfo.location &&
|
|
169
|
-
parseResult) {
|
|
204
|
+
if (!emittedFields.location && hasInfo.location && parseResult) {
|
|
170
205
|
const location = (0, get_location_1.getLocation)(parseResult.segments);
|
|
171
|
-
(
|
|
172
|
-
|
|
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;
|
|
173
211
|
}
|
|
174
212
|
continue;
|
|
175
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