Comparing version
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
export declare class WASMagic { | ||
@@ -7,3 +6,3 @@ static create(): Promise<WASMagic>; | ||
private constructor(); | ||
getMime(buf: Buffer): string; | ||
getMime(buf: Uint8Array): string; | ||
} |
@@ -17,11 +17,5 @@ "use strict"; | ||
const wasmagic_1 = __importDefault(require("../dist/wasmagic.js")); // ./dist/wasmagic.js | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
const magicFile = fs_1.readFileSync(path_1.join(__dirname, "magic.mgc")); | ||
class WASMagic { | ||
constructor(Module) { | ||
this.Module = Module; | ||
const writeStream = this.Module.FS.open("/magic.mgc", "w+"); | ||
this.Module.FS.write(writeStream, magicFile, 0, magicFile.length, 0); | ||
this.Module.FS.close(writeStream); | ||
this.getMimeFromWasm = Module.cwrap("wasmagic_get_mime", "string", [ | ||
@@ -28,0 +22,0 @@ "number", |
{ | ||
"name": "wasmagic", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "WASM compiled version of libmagic", | ||
@@ -5,0 +5,0 @@ "repository": "moshen/wasmagic", |
@@ -19,8 +19,8 @@ # WASMagic | ||
async function main() { | ||
const magic = await WASMagic.create(); | ||
const pngFile = Buffer.from('89504E470D0A1A0A0000000D49484452', 'hex'); | ||
console.log(magic.getMime(pngFile)); | ||
const magic = await WASMagic.create(); | ||
const pngFile = Buffer.from("89504E470D0A1A0A0000000D49484452", "hex"); | ||
console.log(magic.getMime(pngFile)); | ||
} | ||
main().catch(err => console.error(err)); | ||
main().catch((err) => console.error(err)); | ||
// outputs: image/png | ||
@@ -40,11 +40,11 @@ ``` | ||
const { WASMagic } = require("wasmagic"); | ||
const fs = require('fs'); | ||
const fs = require("fs"); | ||
async function main() { | ||
const magic = await WASMagic.create(); | ||
const largeFile = fs.readFileSync('largeFile.mp4'); | ||
console.log(magic.getMime(largeFile.slice(0, 1024))); | ||
const magic = await WASMagic.create(); | ||
const largeFile = fs.readFileSync("largeFile.mp4"); | ||
console.log(magic.getMime(largeFile.slice(0, 1024))); | ||
} | ||
main().catch(err => console.error(err)); | ||
main().catch((err) => console.error(err)); | ||
// outputs: video/mp4 | ||
@@ -64,4 +64,4 @@ ``` | ||
WASMagic detects any file type detected by | ||
[libmagic](https://github.com/file/file/tree/master/magic/Magdir), which is over | ||
WASMagic detects any file type [detected by | ||
libmagic](https://github.com/file/file/tree/master/magic/Magdir), which is over | ||
1500 mime types. For comparison; the | ||
@@ -68,0 +68,0 @@ [file-type](https://www.npmjs.com/package/file-type) library supports 138 types. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5458
2.08%7633238
-0.54%9
-10%