magic-file 1.0.0
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/LICENSE +19 -0
- package/README.md +214 -0
- package/THIRD_PARTY_NOTICES +36 -0
- package/dist/cjs/Magic.d.ts +12 -0
- package/dist/cjs/Magic.d.ts.map +1 -0
- package/dist/cjs/Magic.js +59 -0
- package/dist/cjs/Magic.js.map +1 -0
- package/dist/cjs/StdioOverrideFunction.d.ts +2 -0
- package/dist/cjs/StdioOverrideFunction.d.ts.map +1 -0
- package/dist/cjs/StdioOverrideFunction.js +3 -0
- package/dist/cjs/StdioOverrideFunction.js.map +1 -0
- package/dist/cjs/constants.d.ts +34 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +38 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/detector.d.ts +7 -0
- package/dist/cjs/detector.d.ts.map +1 -0
- package/dist/cjs/detector.js +31 -0
- package/dist/cjs/detector.js.map +1 -0
- package/dist/cjs/errors.d.ts +13 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +36 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/input.d.ts +3 -0
- package/dist/cjs/input.d.ts.map +1 -0
- package/dist/cjs/input.js +26 -0
- package/dist/cjs/input.js.map +1 -0
- package/dist/cjs/loader.d.ts +3 -0
- package/dist/cjs/loader.d.ts.map +1 -0
- package/dist/cjs/loader.js +113 -0
- package/dist/cjs/loader.js.map +1 -0
- package/dist/cjs/memory.d.ts +9 -0
- package/dist/cjs/memory.d.ts.map +1 -0
- package/dist/cjs/memory.js +33 -0
- package/dist/cjs/memory.js.map +1 -0
- package/dist/cjs/mutex.d.ts +6 -0
- package/dist/cjs/mutex.d.ts.map +1 -0
- package/dist/cjs/mutex.js +27 -0
- package/dist/cjs/mutex.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +37 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/wasm-loader.d.ts +2 -0
- package/dist/cjs/wasm-loader.d.ts.map +1 -0
- package/dist/cjs/wasm-loader.js +22 -0
- package/dist/cjs/wasm-loader.js.map +1 -0
- package/dist/esm/Magic.d.ts +12 -0
- package/dist/esm/Magic.d.ts.map +1 -0
- package/dist/esm/Magic.js +55 -0
- package/dist/esm/Magic.js.map +1 -0
- package/dist/esm/StdioOverrideFunction.d.ts +2 -0
- package/dist/esm/StdioOverrideFunction.d.ts.map +1 -0
- package/dist/esm/StdioOverrideFunction.js +2 -0
- package/dist/esm/StdioOverrideFunction.js.map +1 -0
- package/dist/esm/constants.d.ts +34 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +34 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/detector.d.ts +7 -0
- package/dist/esm/detector.d.ts.map +1 -0
- package/dist/esm/detector.js +28 -0
- package/dist/esm/detector.js.map +1 -0
- package/dist/esm/errors.d.ts +13 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +29 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/input.d.ts +3 -0
- package/dist/esm/input.d.ts.map +1 -0
- package/dist/esm/input.js +23 -0
- package/dist/esm/input.js.map +1 -0
- package/dist/esm/loader.d.ts +3 -0
- package/dist/esm/loader.d.ts.map +1 -0
- package/dist/esm/loader.js +77 -0
- package/dist/esm/loader.js.map +1 -0
- package/dist/esm/memory.d.ts +9 -0
- package/dist/esm/memory.d.ts.map +1 -0
- package/dist/esm/memory.js +29 -0
- package/dist/esm/memory.js.map +1 -0
- package/dist/esm/mutex.d.ts +6 -0
- package/dist/esm/mutex.d.ts.map +1 -0
- package/dist/esm/mutex.js +24 -0
- package/dist/esm/mutex.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.d.ts +37 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/wasm-loader.d.ts +2 -0
- package/dist/esm/wasm-loader.d.ts.map +1 -0
- package/dist/esm/wasm-loader.js +19 -0
- package/dist/esm/wasm-loader.js.map +1 -0
- package/dist/wasm/libmagic-wrapper.node.d.ts +2 -0
- package/dist/wasm/libmagic-wrapper.node.js +2 -0
- package/dist/wasm/libmagic-wrapper.node.wasm +0 -0
- package/dist/wasm/libmagic-wrapper.web.d.ts +2 -0
- package/dist/wasm/libmagic-wrapper.web.js +2 -0
- package/dist/wasm/libmagic-wrapper.web.wasm +0 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Ayanmwunmi Ogaga
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19
|
+
DISCLAIMED.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# magic-file
|
|
2
|
+
|
|
3
|
+
Get the MIME type of virtually any file format using **libmagic**, the
|
|
4
|
+
same engine behind the Unix `file` command, compiled to **WebAssembly**.
|
|
5
|
+
|
|
6
|
+
Unlike most browser-friendly file type detectors that recognize only a
|
|
7
|
+
limited set of signatures, **magic-file** leverages the full power of
|
|
8
|
+
**libmagic** to identify **thousands of file formats** that have been
|
|
9
|
+
introduced over the years.
|
|
10
|
+
|
|
11
|
+
It works everywhere JavaScript runs:
|
|
12
|
+
|
|
13
|
+
- ✅ Browser
|
|
14
|
+
- ✅ React
|
|
15
|
+
- ✅ Next.js
|
|
16
|
+
- ✅ Vite
|
|
17
|
+
- ✅ Node.js
|
|
18
|
+
- ✅ Bun
|
|
19
|
+
- ✅ Deno
|
|
20
|
+
- ✅ Most modern bundlers
|
|
21
|
+
|
|
22
|
+
There are already excellent packages such as `file-type`, but they
|
|
23
|
+
intentionally support a relatively small collection of common file
|
|
24
|
+
signatures. **magic-file** is designed for applications that need much
|
|
25
|
+
broader coverage while still remaining easy to use.
|
|
26
|
+
|
|
27
|
+
Internally, this project uses a WebAssembly build of **libmagic**,
|
|
28
|
+
inspired by Colin Kennedy's work: - https://github.com/moshen/wasmagic -
|
|
29
|
+
https://github.com/file/file -
|
|
30
|
+
https://man7.org/linux/man-pages/man3/libmagic.3.html
|
|
31
|
+
|
|
32
|
+
The WASM build has been heavily optimized so it can run reliably in
|
|
33
|
+
browsers as well as server-side runtimes.
|
|
34
|
+
|
|
35
|
+
## Live Demo
|
|
36
|
+
|
|
37
|
+
Try **magic-file** in your browser without installing anything:
|
|
38
|
+
|
|
39
|
+
🌐 **https://filetypecheck.com/**
|
|
40
|
+
|
|
41
|
+
The demo runs entirely in your browser—your files are **never uploaded** or sent to a server. Drag and drop a file (or enter a URL) to instantly detect its real MIME type and validate whether its extension matches its actual content. :contentReference[oaicite:0]{index=0}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Why is the package around 600KB?
|
|
45
|
+
|
|
46
|
+
`magic-file` embeds the compiled **magic database** containing
|
|
47
|
+
signatures for thousands of known file formats.
|
|
48
|
+
|
|
49
|
+
Instead of shipping several megabytes of data, the database is
|
|
50
|
+
compressed and baked directly into the WASM binary.
|
|
51
|
+
|
|
52
|
+
The final download is approximately **600KB**, and when served through
|
|
53
|
+
**gzip** or **Brotli** (Next.js, React, Vite, CDN, etc.) it becomes even
|
|
54
|
+
smaller over the network.
|
|
55
|
+
|
|
56
|
+
The result is a single package with:
|
|
57
|
+
|
|
58
|
+
- No native compilation
|
|
59
|
+
- Minimal runtime dependencies
|
|
60
|
+
- Cross-platform compatibility
|
|
61
|
+
- File detection powered by `libmagic`
|
|
62
|
+
|
|
63
|
+
## Why magic-file?
|
|
64
|
+
|
|
65
|
+
There are already excellent packages such as `file-type`, but they intentionally support a relatively small collection of common file signatures. **magic-file** is designed for applications that require much broader coverage by leveraging the same detection engine used by the Unix `file` command. :contentReference[oaicite:1]{index=1}
|
|
66
|
+
|
|
67
|
+
------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
## Installation
|
|
70
|
+
|
|
71
|
+
``` bash
|
|
72
|
+
npm install magic-file
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Quick Example
|
|
76
|
+
|
|
77
|
+
``` ts
|
|
78
|
+
import { Magic } from "magic-file";
|
|
79
|
+
|
|
80
|
+
const magic = await Magic.create();
|
|
81
|
+
|
|
82
|
+
const mime = await magic.detect(buffer);
|
|
83
|
+
const mime2 = await magic.detect(arrayBuffer);
|
|
84
|
+
const mime3 = await magic.detect(file);
|
|
85
|
+
const mime4 = await magic.detect(blob);
|
|
86
|
+
|
|
87
|
+
magic.dispose();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
------------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
# Browser (React / Next.js / Vite)
|
|
93
|
+
|
|
94
|
+
``` tsx
|
|
95
|
+
import { Magic } from "magic-file";
|
|
96
|
+
|
|
97
|
+
const handleFileChange = async (e) => {
|
|
98
|
+
const files = Array.from(e.target.files).slice(0, 6);
|
|
99
|
+
|
|
100
|
+
if (!files.length) return;
|
|
101
|
+
|
|
102
|
+
const start = performance.now();
|
|
103
|
+
|
|
104
|
+
setLoading(true);
|
|
105
|
+
setResults([]);
|
|
106
|
+
|
|
107
|
+
let magic;
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
magic = await Magic.create();
|
|
111
|
+
|
|
112
|
+
const results = [];
|
|
113
|
+
|
|
114
|
+
for (const file of files) {
|
|
115
|
+
const mime = await magic.detect(file);
|
|
116
|
+
results.push({
|
|
117
|
+
name: file.name,
|
|
118
|
+
mime
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(`${performance.now() - start}ms`);
|
|
123
|
+
|
|
124
|
+
setResults(results);
|
|
125
|
+
|
|
126
|
+
} finally {
|
|
127
|
+
magic?.dispose();
|
|
128
|
+
setLoading(false);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
<input type="file" multiple onChange={handleFileChange} />
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
# Node.js
|
|
138
|
+
|
|
139
|
+
``` js
|
|
140
|
+
const { Magic } = require("magic-file");
|
|
141
|
+
const { readFile } = require("node:fs/promises");
|
|
142
|
+
|
|
143
|
+
async function detect(path) {
|
|
144
|
+
|
|
145
|
+
const magic = await Magic.create();
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const buffer = await readFile(path);
|
|
149
|
+
|
|
150
|
+
const mime = await magic.detect(buffer);
|
|
151
|
+
|
|
152
|
+
console.log(mime);
|
|
153
|
+
|
|
154
|
+
} finally {
|
|
155
|
+
magic.dispose();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
detect("./package.json");
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
------------------------------------------------------------------------
|
|
163
|
+
|
|
164
|
+
# Bun
|
|
165
|
+
|
|
166
|
+
``` ts
|
|
167
|
+
import { Magic } from "magic-file";
|
|
168
|
+
|
|
169
|
+
const magic = await Magic.create();
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
|
|
173
|
+
const file = Bun.file("./package.json");
|
|
174
|
+
|
|
175
|
+
const mime = await magic.detect(
|
|
176
|
+
new Uint8Array(await file.arrayBuffer())
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
console.log(mime);
|
|
180
|
+
|
|
181
|
+
} finally {
|
|
182
|
+
magic.dispose();
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
------------------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
## Features
|
|
189
|
+
|
|
190
|
+
- Full **libmagic** powered detection
|
|
191
|
+
- Supports thousands of file formats
|
|
192
|
+
- Browser, Node.js, Bun and Deno support
|
|
193
|
+
- React, Next.js and Vite compatible
|
|
194
|
+
- Zero production dependencies
|
|
195
|
+
- No native compilation
|
|
196
|
+
- Single embedded magic database
|
|
197
|
+
- Dual ESM / CommonJS
|
|
198
|
+
- Supports `Buffer`, `Uint8Array`, `ArrayBuffer`, `Blob` and `File`
|
|
199
|
+
- Small API: `create()`, `detect()`, `dispose()`
|
|
200
|
+
|
|
201
|
+
------------------------------------------------------------------------
|
|
202
|
+
|
|
203
|
+
## Acknowledgements
|
|
204
|
+
|
|
205
|
+
`magic-file` is powered by **libmagic**, the same file identification library used by the Unix `file` command.
|
|
206
|
+
|
|
207
|
+
This project builds upon the WebAssembly work originally started by Colin Kennedy:
|
|
208
|
+
- https://github.com/moshen/wasmagic
|
|
209
|
+
|
|
210
|
+
Special thanks to the libmagic project and its maintainers, including Ian F. Darwin and Christos Zoulas, for creating and maintaining one of the most comprehensive file identification libraries available.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
BSD-2-Clause
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# 1. libmagic
|
|
2
|
+
|
|
3
|
+
* **Homepage:** https://www.darwinsys.com/file/
|
|
4
|
+
* **License:** BSD-2-Clause
|
|
5
|
+
*
|
|
6
|
+
BSD-2-Clause
|
|
7
|
+
|
|
8
|
+
$File: COPYING,v 1.2 2018/09/09 20:33:28 christos Exp $
|
|
9
|
+
Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
|
|
10
|
+
Software written by Ian F. Darwin and others;
|
|
11
|
+
maintained 1994- Christos Zoulas.
|
|
12
|
+
|
|
13
|
+
This software is not subject to any export provision of the United States
|
|
14
|
+
Department of Commerce, and may be exported to any country or planet.
|
|
15
|
+
|
|
16
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
17
|
+
are permitted provided that the following conditions are met:
|
|
18
|
+
|
|
19
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
20
|
+
list of conditions and the following disclaimer.
|
|
21
|
+
|
|
22
|
+
1. Redistributions in binary form must reproduce the above copyright notice,
|
|
23
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
|
24
|
+
other materials provided with the distribution.
|
|
25
|
+
|
|
26
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
27
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
28
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
29
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
30
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
31
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
32
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
33
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
34
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
35
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
36
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MagicInput, MagicOptions } from "./types.js";
|
|
2
|
+
export declare class Magic {
|
|
3
|
+
static create(options?: MagicOptions): Promise<Magic>;
|
|
4
|
+
private detector;
|
|
5
|
+
private mutex;
|
|
6
|
+
private disposed;
|
|
7
|
+
private constructor();
|
|
8
|
+
detect(input: MagicInput): Promise<string>;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
static normalize(input: MagicInput): Promise<Uint8Array>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Magic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Magic.d.ts","sourceRoot":"","sources":["../../src/Magic.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,UAAU,EACV,YAAY,EACb,MAAM,YAAY,CAAC;AAQpB,qBAAa,KAAK;WACH,MAAM,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,KAAK,CAAC;IAiB/D,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,QAAQ,CAAU;IAE1B,OAAO;IAMD,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBhD,OAAO,IAAI,IAAI;IAUf,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAGzD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Magic = void 0;
|
|
4
|
+
const detector_js_1 = require("./detector.js");
|
|
5
|
+
const loader_js_1 = require("./loader.js");
|
|
6
|
+
const input_js_1 = require("./input.js");
|
|
7
|
+
const mutex_js_1 = require("./mutex.js");
|
|
8
|
+
const constants_js_1 = require("./constants.js");
|
|
9
|
+
const errors_js_1 = require("./errors.js");
|
|
10
|
+
class Magic {
|
|
11
|
+
static async create(options = {}) {
|
|
12
|
+
const resolved = {
|
|
13
|
+
flags: options.flags ?? constants_js_1.DEFAULT_FLAGS,
|
|
14
|
+
loadDefaultMagicfile: options.loadDefaultMagicfile ?? constants_js_1.DEFAULT_LOAD_DEFAULT_MAGICFILE,
|
|
15
|
+
magicFiles: options.magicFiles ?? [],
|
|
16
|
+
stdio: options.stdio ?? constants_js_1.NOOP_STDIO,
|
|
17
|
+
locateFile: options.locateFile,
|
|
18
|
+
wasmBinary: options.wasmBinary,
|
|
19
|
+
};
|
|
20
|
+
const module = await (0, loader_js_1.loadModule)(resolved);
|
|
21
|
+
const detector = (0, detector_js_1.createDetector)(module);
|
|
22
|
+
return new Magic(detector);
|
|
23
|
+
}
|
|
24
|
+
constructor(detector) {
|
|
25
|
+
this.detector = detector;
|
|
26
|
+
this.mutex = (0, mutex_js_1.createMutex)();
|
|
27
|
+
this.disposed = false;
|
|
28
|
+
}
|
|
29
|
+
async detect(input) {
|
|
30
|
+
if (this.disposed) {
|
|
31
|
+
throw new errors_js_1.MagicDisposedError();
|
|
32
|
+
}
|
|
33
|
+
if (!this.detector) {
|
|
34
|
+
throw new errors_js_1.MagicDisposedError();
|
|
35
|
+
}
|
|
36
|
+
const release = await this.mutex.acquire();
|
|
37
|
+
try {
|
|
38
|
+
const buffer = await (0, input_js_1.normalizeInput)(input);
|
|
39
|
+
return this.detector(buffer);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
release();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
dispose() {
|
|
46
|
+
if (this.disposed)
|
|
47
|
+
return;
|
|
48
|
+
this.disposed = true;
|
|
49
|
+
if (this.detector) {
|
|
50
|
+
this.detector.dispose();
|
|
51
|
+
this.detector = null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static normalize(input) {
|
|
55
|
+
return (0, input_js_1.normalizeInput)(input);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Magic = Magic;
|
|
59
|
+
//# sourceMappingURL=Magic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Magic.js","sourceRoot":"","sources":["../../src/Magic.ts"],"names":[],"mappings":";;;AACA,+CAA+C;AAC/C,2CAAyC;AACzC,yCAA4C;AAC5C,yCAAqD;AAMrD,iDAIwB;AACxB,2CAAiD;AAEjD,MAAa,KAAK;IAChB,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAwB,EAAE;QAC5C,MAAM,QAAQ,GAAyB;YACrC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,4BAAa;YACrC,oBAAoB,EAClB,OAAO,CAAC,oBAAoB,IAAI,6CAA8B;YAChE,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE;YACpC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,yBAAU;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAU,EAAC,QAAQ,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,IAAA,4BAAc,EAAC,MAAM,CAAC,CAAC;QAExC,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAMD,YAAoB,QAAkB;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,IAAA,sBAAW,GAAE,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAiB;QAC5B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,8BAAkB,EAAE,CAAC;QACjC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,8BAAkB,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QAE3C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC;gBAAS,CAAC;YACT,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAiB;QAChC,OAAO,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACF;AA5DD,sBA4DC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StdioOverrideFunction.d.ts","sourceRoot":"","sources":["../../src/StdioOverrideFunction.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,QAAQ,GAAG,QAAQ,EAC9B,IAAI,EAAE,MAAM,KACT,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StdioOverrideFunction.js","sourceRoot":"","sources":["../../src/StdioOverrideFunction.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const MagicFlags: Readonly<{
|
|
2
|
+
readonly NONE: 0;
|
|
3
|
+
readonly DEBUG: 1;
|
|
4
|
+
readonly SYMLINK: 2;
|
|
5
|
+
readonly COMPRESS: 4;
|
|
6
|
+
readonly DEVICES: 8;
|
|
7
|
+
readonly MIME_TYPE: 16;
|
|
8
|
+
readonly CONTINUE: 32;
|
|
9
|
+
readonly CHECK: 64;
|
|
10
|
+
readonly PRESERVE_ATIME: 128;
|
|
11
|
+
readonly RAW: 256;
|
|
12
|
+
readonly ERROR: 512;
|
|
13
|
+
readonly MIME_ENCODING: 1024;
|
|
14
|
+
readonly APPLE: 2048;
|
|
15
|
+
readonly EXTENSION: 16777216;
|
|
16
|
+
readonly COMPRESS_TRANSP: 33554432;
|
|
17
|
+
readonly NO_COMPRESS_FORK: 67108864;
|
|
18
|
+
readonly NO_CHECK_COMPRESS: 4096;
|
|
19
|
+
readonly NO_CHECK_TAR: 8192;
|
|
20
|
+
readonly NO_CHECK_SOFT: 16384;
|
|
21
|
+
readonly NO_CHECK_APPTYPE: 32768;
|
|
22
|
+
readonly NO_CHECK_ELF: 65536;
|
|
23
|
+
readonly NO_CHECK_TEXT: 131072;
|
|
24
|
+
readonly NO_CHECK_CDF: 262144;
|
|
25
|
+
readonly NO_CHECK_CSV: 524288;
|
|
26
|
+
readonly NO_CHECK_TOKENS: 1048576;
|
|
27
|
+
readonly NO_CHECK_ENCODING: 2097152;
|
|
28
|
+
readonly NO_CHECK_JSON: 4194304;
|
|
29
|
+
readonly NO_CHECK_SIMH: 8388608;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const DEFAULT_FLAGS: number;
|
|
32
|
+
export declare const DEFAULT_LOAD_DEFAULT_MAGICFILE = true;
|
|
33
|
+
export declare const NOOP_STDIO: (_stdioName: "stdout" | "stderr", _text: string) => void;
|
|
34
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BZ,CAAC;AAEZ,eAAO,MAAM,aAAa,EAAE,MAA6B,CAAC;AAC1D,eAAO,MAAM,8BAA8B,OAAO,CAAC;AACnD,eAAO,MAAM,UAAU,GAAI,YAAY,QAAQ,GAAG,QAAQ,EAAE,OAAO,MAAM,SAAO,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NOOP_STDIO = exports.DEFAULT_LOAD_DEFAULT_MAGICFILE = exports.DEFAULT_FLAGS = exports.MagicFlags = void 0;
|
|
4
|
+
exports.MagicFlags = Object.freeze({
|
|
5
|
+
NONE: 0x0000000,
|
|
6
|
+
DEBUG: 0x0000001,
|
|
7
|
+
SYMLINK: 0x0000002,
|
|
8
|
+
COMPRESS: 0x0000004,
|
|
9
|
+
DEVICES: 0x0000008,
|
|
10
|
+
MIME_TYPE: 0x0000010,
|
|
11
|
+
CONTINUE: 0x0000020,
|
|
12
|
+
CHECK: 0x0000040,
|
|
13
|
+
PRESERVE_ATIME: 0x0000080,
|
|
14
|
+
RAW: 0x0000100,
|
|
15
|
+
ERROR: 0x0000200,
|
|
16
|
+
MIME_ENCODING: 0x0000400,
|
|
17
|
+
APPLE: 0x0000800,
|
|
18
|
+
EXTENSION: 0x1000000,
|
|
19
|
+
COMPRESS_TRANSP: 0x2000000,
|
|
20
|
+
NO_COMPRESS_FORK: 0x4000000,
|
|
21
|
+
NO_CHECK_COMPRESS: 0x0001000,
|
|
22
|
+
NO_CHECK_TAR: 0x0002000,
|
|
23
|
+
NO_CHECK_SOFT: 0x0004000,
|
|
24
|
+
NO_CHECK_APPTYPE: 0x0008000,
|
|
25
|
+
NO_CHECK_ELF: 0x0010000,
|
|
26
|
+
NO_CHECK_TEXT: 0x0020000,
|
|
27
|
+
NO_CHECK_CDF: 0x0040000,
|
|
28
|
+
NO_CHECK_CSV: 0x0080000,
|
|
29
|
+
NO_CHECK_TOKENS: 0x0100000,
|
|
30
|
+
NO_CHECK_ENCODING: 0x0200000,
|
|
31
|
+
NO_CHECK_JSON: 0x0400000,
|
|
32
|
+
NO_CHECK_SIMH: 0x0800000,
|
|
33
|
+
});
|
|
34
|
+
exports.DEFAULT_FLAGS = exports.MagicFlags.MIME_TYPE;
|
|
35
|
+
exports.DEFAULT_LOAD_DEFAULT_MAGICFILE = true;
|
|
36
|
+
const NOOP_STDIO = (_stdioName, _text) => { };
|
|
37
|
+
exports.NOOP_STDIO = NOOP_STDIO;
|
|
38
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,SAAS;IACnB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,SAAS;IACnB,KAAK,EAAE,SAAS;IAChB,cAAc,EAAE,SAAS;IACzB,GAAG,EAAE,SAAS;IACd,KAAK,EAAE,SAAS;IAChB,aAAa,EAAE,SAAS;IACxB,KAAK,EAAE,SAAS;IAChB,SAAS,EAAE,SAAS;IACpB,eAAe,EAAE,SAAS;IAC1B,gBAAgB,EAAE,SAAS;IAC3B,iBAAiB,EAAE,SAAS;IAC5B,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,SAAS;IACxB,gBAAgB,EAAE,SAAS;IAC3B,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,SAAS;IACxB,YAAY,EAAE,SAAS;IACvB,YAAY,EAAE,SAAS;IACvB,eAAe,EAAE,SAAS;IAC1B,iBAAiB,EAAE,SAAS;IAC5B,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;CAChB,CAAC,CAAC;AAEC,QAAA,aAAa,GAAW,kBAAU,CAAC,SAAS,CAAC;AAC7C,QAAA,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,UAAU,GAAG,CAAC,UAA+B,EAAE,KAAa,EAAE,EAAE,GAAE,CAAC,CAAC;AAApE,QAAA,UAAU,cAA0D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LibmagicModule } from "./types.js";
|
|
2
|
+
export declare function createDetector(module: LibmagicModule): {
|
|
3
|
+
(buffer: Uint8Array): string;
|
|
4
|
+
dispose(): void;
|
|
5
|
+
};
|
|
6
|
+
export type Detector = ReturnType<typeof createDetector>;
|
|
7
|
+
//# sourceMappingURL=detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../src/detector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc;aAQ3B,UAAU,GAAG,MAAM;;EAwB5C;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDetector = createDetector;
|
|
4
|
+
const memory_js_1 = require("./memory.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
function createDetector(module) {
|
|
7
|
+
const detectFromWasm = module.cwrap("magic_wrapper_detect", "string", [
|
|
8
|
+
"number",
|
|
9
|
+
"number",
|
|
10
|
+
]);
|
|
11
|
+
const scratch = new memory_js_1.ScratchBuffer();
|
|
12
|
+
function detect(buffer) {
|
|
13
|
+
const ptr = scratch.write(module, buffer);
|
|
14
|
+
let result;
|
|
15
|
+
try {
|
|
16
|
+
result = detectFromWasm(ptr, buffer.byteLength);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
throw new errors_js_1.MagicDetectError(`Detection failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
20
|
+
}
|
|
21
|
+
if (result == null) {
|
|
22
|
+
throw new errors_js_1.MagicDetectError("Detection returned null or undefined result");
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
detect.dispose = () => {
|
|
27
|
+
scratch.release(module);
|
|
28
|
+
};
|
|
29
|
+
return detect;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../src/detector.ts"],"names":[],"mappings":";;AAIA,wCAgCC;AAnCD,2CAA4C;AAC5C,2CAA+C;AAE/C,SAAgB,cAAc,CAAC,MAAsB;IACnD,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,QAAQ,EAAE;QACpE,QAAQ;QACR,QAAQ;KACT,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,yBAAa,EAAE,CAAC;IAEpC,SAAS,MAAM,CAAC,MAAkB;QAChC,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAE1C,IAAI,MAAc,CAAC;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,4BAAgB,CACxB,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,4BAAgB,CAAC,6CAA6C,CAAC,CAAC;QAC5E,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;QACpB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class MagicError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class MagicLoadError extends MagicError {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class MagicDetectError extends MagicError {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class MagicDisposedError extends MagicError {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,cAAe,SAAQ,UAAU;gBAChC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,gBAAiB,SAAQ,UAAU;gBAClC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,kBAAmB,SAAQ,UAAU;;CAMjD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MagicDisposedError = exports.MagicDetectError = exports.MagicLoadError = exports.MagicError = void 0;
|
|
4
|
+
class MagicError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "MagicError";
|
|
8
|
+
Object.setPrototypeOf(this, MagicError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.MagicError = MagicError;
|
|
12
|
+
class MagicLoadError extends MagicError {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "MagicLoadError";
|
|
16
|
+
Object.setPrototypeOf(this, MagicLoadError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.MagicLoadError = MagicLoadError;
|
|
20
|
+
class MagicDetectError extends MagicError {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "MagicDetectError";
|
|
24
|
+
Object.setPrototypeOf(this, MagicDetectError.prototype);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.MagicDetectError = MagicDetectError;
|
|
28
|
+
class MagicDisposedError extends MagicError {
|
|
29
|
+
constructor() {
|
|
30
|
+
super("Magic instance has been disposed and can no longer be used");
|
|
31
|
+
this.name = "MagicDisposedError";
|
|
32
|
+
Object.setPrototypeOf(this, MagicDisposedError.prototype);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.MagicDisposedError = MagicDisposedError;
|
|
36
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAND,gCAMC;AAED,MAAa,cAAe,SAAQ,UAAU;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACF;AAND,wCAMC;AAED,MAAa,gBAAiB,SAAQ,UAAU;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAND,4CAMC;AAED,MAAa,kBAAmB,SAAQ,UAAU;IAChD;QACE,KAAK,CAAC,4DAA4D,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;CACF;AAND,gDAMC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Magic } from "./Magic.js";
|
|
2
|
+
export { MagicFlags } from "./constants.js";
|
|
3
|
+
export { MagicError, MagicLoadError, MagicDetectError, MagicDisposedError, } from "./errors.js";
|
|
4
|
+
export type { MagicOptions, MagicInput, StdioOverrideFunction, LibmagicModule, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,YAAY,EACZ,UAAU,EACV,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MagicDisposedError = exports.MagicDetectError = exports.MagicLoadError = exports.MagicError = exports.MagicFlags = exports.Magic = void 0;
|
|
4
|
+
var Magic_js_1 = require("./Magic.js");
|
|
5
|
+
Object.defineProperty(exports, "Magic", { enumerable: true, get: function () { return Magic_js_1.Magic; } });
|
|
6
|
+
var constants_js_1 = require("./constants.js");
|
|
7
|
+
Object.defineProperty(exports, "MagicFlags", { enumerable: true, get: function () { return constants_js_1.MagicFlags; } });
|
|
8
|
+
var errors_js_1 = require("./errors.js");
|
|
9
|
+
Object.defineProperty(exports, "MagicError", { enumerable: true, get: function () { return errors_js_1.MagicError; } });
|
|
10
|
+
Object.defineProperty(exports, "MagicLoadError", { enumerable: true, get: function () { return errors_js_1.MagicLoadError; } });
|
|
11
|
+
Object.defineProperty(exports, "MagicDetectError", { enumerable: true, get: function () { return errors_js_1.MagicDetectError; } });
|
|
12
|
+
Object.defineProperty(exports, "MagicDisposedError", { enumerable: true, get: function () { return errors_js_1.MagicDisposedError; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAA1B,iGAAA,KAAK,OAAA;AACd,+CAA4C;AAAnC,0GAAA,UAAU,OAAA;AACnB,yCAKqB;AAJnB,uGAAA,UAAU,OAAA;AACV,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,+GAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAsB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAoB3E"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeInput = normalizeInput;
|
|
4
|
+
async function normalizeInput(input) {
|
|
5
|
+
// Note: Node's Buffer is a subclass of Uint8Array, so this branch also
|
|
6
|
+
// covers Buffer inputs (including ones with a non-zero byteOffset into a
|
|
7
|
+
// shared underlying ArrayBuffer) without needing a separate check.
|
|
8
|
+
if (input instanceof Uint8Array) {
|
|
9
|
+
return input;
|
|
10
|
+
}
|
|
11
|
+
if (input instanceof ArrayBuffer) {
|
|
12
|
+
return new Uint8Array(input);
|
|
13
|
+
}
|
|
14
|
+
if (isBlob(input) || isFile(input)) {
|
|
15
|
+
const buf = await input.arrayBuffer();
|
|
16
|
+
return new Uint8Array(buf);
|
|
17
|
+
}
|
|
18
|
+
throw new TypeError(`Unsupported input type. Expected Uint8Array, ArrayBuffer, Buffer, Blob, or File. Got ${typeof input}`);
|
|
19
|
+
}
|
|
20
|
+
function isBlob(value) {
|
|
21
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
22
|
+
}
|
|
23
|
+
function isFile(value) {
|
|
24
|
+
return typeof File !== "undefined" && value instanceof File;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/input.ts"],"names":[],"mappings":";;AAEA,wCAoBC;AApBM,KAAK,UAAU,cAAc,CAAC,KAAiB;IACpD,uEAAuE;IACvE,yEAAyE;IACzE,mEAAmE;IACnE,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,MAAO,KAAc,CAAC,WAAW,EAAE,CAAC;QAChD,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,IAAI,SAAS,CACjB,wFAAwF,OAAO,KAAK,EAAE,CACvG,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,CAAC;AAC9D,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,oBAAoB,EACrB,MAAM,YAAY,CAAC;AA4BpB,wBAAsB,UAAU,CAC9B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC,CA8DzB"}
|