libmagic-ffi
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -1,8 +0,23 @@ | ||
import ffi from 'ffi-napi'; | ||
import ref from 'ref-napi'; | ||
export declare const magic_t: ref.Type<ref.Pointer<void>>; | ||
export declare const ptr: ref.Type<ref.Pointer<void>>; | ||
export declare const ptr_ptr: ref.Type<ref.Pointer<ref.Pointer<void>>>; | ||
export declare const size_t_ptr: ref.Type<ref.Pointer<string | number>>; | ||
import koffi from 'koffi'; | ||
export declare const magic_t: koffi.IKoffiCType; | ||
export declare const magic_t_ptr: koffi.IKoffiCType; | ||
export declare const libmagic: { | ||
magic_open: koffi.KoffiFunction; | ||
magic_close: koffi.KoffiFunction; | ||
magic_getpath: koffi.KoffiFunction; | ||
magic_file: koffi.KoffiFunction; | ||
magic_descriptor: koffi.KoffiFunction; | ||
magic_buffer: koffi.KoffiFunction; | ||
magic_error: koffi.KoffiFunction; | ||
magic_getflags: koffi.KoffiFunction; | ||
magic_setflags: koffi.KoffiFunction; | ||
magic_version: koffi.KoffiFunction; | ||
magic_load: koffi.KoffiFunction; | ||
magic_load_buffers: koffi.KoffiFunction; | ||
magic_compile: koffi.KoffiFunction; | ||
magic_check: koffi.KoffiFunction; | ||
magic_list: koffi.KoffiFunction; | ||
magic_errno: koffi.KoffiFunction; | ||
magic_setparam: koffi.KoffiFunction; | ||
magic_getparam: koffi.KoffiFunction; | ||
MAGIC_NONE: number; | ||
@@ -44,22 +59,3 @@ MAGIC_DEBUG: number; | ||
MAGIC_PARAM_BYTES_MAX: number; | ||
} & { | ||
magic_open: ffi.ForeignFunction<ref.Pointer<void>, [number]>; | ||
magic_close: ffi.ForeignFunction<void, [ref.Pointer<void>]>; | ||
magic_getpath: ffi.ForeignFunction<string | null, [string | null, number]>; | ||
magic_file: ffi.ForeignFunction<string | null, [ref.Pointer<void>, string | null]>; | ||
magic_descriptor: ffi.ForeignFunction<string | null, [ref.Pointer<void>, number]>; | ||
magic_buffer: ffi.ForeignFunction<string | null, [ref.Pointer<void>, ref.Pointer<void>, string | number]>; | ||
magic_error: ffi.ForeignFunction<string | null, [ref.Pointer<void>]>; | ||
magic_getflags: ffi.ForeignFunction<number, [ref.Pointer<void>]>; | ||
magic_setflags: ffi.ForeignFunction<number, [ref.Pointer<void>, number]>; | ||
magic_version: ffi.ForeignFunction<number, []>; | ||
magic_load: ffi.ForeignFunction<number, [ref.Pointer<void>, string | null]>; | ||
magic_load_buffers: ffi.ForeignFunction<number, [ref.Pointer<void>, ref.Pointer<ref.Pointer<void>>, ref.Pointer<string | number>, string | number]>; | ||
magic_compile: ffi.ForeignFunction<number, [ref.Pointer<void>, string | null]>; | ||
magic_check: ffi.ForeignFunction<number, [ref.Pointer<void>, string | null]>; | ||
magic_list: ffi.ForeignFunction<number, [ref.Pointer<void>, string | null]>; | ||
magic_errno: ffi.ForeignFunction<number, [ref.Pointer<void>]>; | ||
magic_setparam: ffi.ForeignFunction<number, [ref.Pointer<void>, number, ref.Pointer<void>]>; | ||
magic_getparam: ffi.ForeignFunction<number, [ref.Pointer<void>, number, ref.Pointer<void>]>; | ||
}; | ||
export default libmagic; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.libmagic = exports.size_t_ptr = exports.ptr_ptr = exports.ptr = exports.magic_t = void 0; | ||
exports.libmagic = exports.magic_t_ptr = exports.magic_t = void 0; | ||
const tslib_1 = require("tslib"); | ||
const ffi_napi_1 = tslib_1.__importDefault(require("ffi-napi")); | ||
const ref_napi_1 = tslib_1.__importDefault(require("ref-napi")); | ||
const koffi_1 = tslib_1.__importDefault(require("koffi")); | ||
const constants_1 = tslib_1.__importDefault(require("./constants")); | ||
const fs_1 = tslib_1.__importDefault(require("fs")); | ||
exports.magic_t = ref_napi_1.default.refType(ref_napi_1.default.types.void); | ||
exports.ptr = ref_napi_1.default.refType(ref_napi_1.default.types.void); | ||
exports.ptr_ptr = ref_napi_1.default.refType(exports.ptr); | ||
exports.size_t_ptr = ref_napi_1.default.refType(ref_napi_1.default.types.size_t); | ||
exports.magic_t = koffi_1.default.opaque(); | ||
exports.magic_t_ptr = koffi_1.default.pointer(exports.magic_t); | ||
let dlOpenPath = 'libmagic'; | ||
@@ -31,26 +28,7 @@ switch (process.platform) { | ||
} | ||
let tryMagic; | ||
let sharedLib; | ||
let lastError; | ||
for (const x of [dlOpenPath, 'libmagic.1', 'libmagic']) { | ||
try { | ||
tryMagic = new ffi_napi_1.default.Library(x, { | ||
magic_open: [exports.magic_t, ['int']], | ||
magic_close: ['void', [exports.magic_t]], | ||
magic_getpath: ['CString', ['CString', 'int']], | ||
magic_file: ['CString', [exports.magic_t, 'CString']], | ||
magic_descriptor: ['CString', [exports.magic_t, 'int']], | ||
magic_buffer: ['CString', [exports.magic_t, exports.ptr, 'size_t']], | ||
magic_error: ['CString', [exports.magic_t]], | ||
magic_getflags: ['int', [exports.magic_t]], | ||
magic_setflags: ['int', [exports.magic_t, 'int']], | ||
magic_version: ['int', []], | ||
magic_load: ['int', [exports.magic_t, 'CString']], | ||
magic_load_buffers: ['int', [exports.magic_t, exports.ptr_ptr, exports.size_t_ptr, 'size_t']], | ||
magic_compile: ['int', [exports.magic_t, 'CString']], | ||
magic_check: ['int', [exports.magic_t, 'CString']], | ||
magic_list: ['int', [exports.magic_t, 'CString']], | ||
magic_errno: ['int', [exports.magic_t]], | ||
magic_setparam: ['int', [exports.magic_t, 'int', exports.ptr]], | ||
magic_getparam: ['int', [exports.magic_t, 'int', exports.ptr]], | ||
}, constants_1.default); | ||
sharedLib = koffi_1.default.load(x); | ||
break; | ||
@@ -63,7 +41,27 @@ } | ||
} | ||
if (!tryMagic) { | ||
if (!sharedLib) { | ||
throw lastError; | ||
} | ||
exports.libmagic = tryMagic; | ||
exports.libmagic = { | ||
...constants_1.default, | ||
magic_open: sharedLib.func('magic_open', exports.magic_t_ptr, ['int']), | ||
magic_close: sharedLib.func('magic_close', 'void', [exports.magic_t_ptr]), | ||
magic_getpath: sharedLib.func('magic_getpath', 'string', ['string', 'int']), | ||
magic_file: sharedLib.func('magic_file', 'string', [exports.magic_t_ptr, 'string']), | ||
magic_descriptor: sharedLib.func('magic_descriptor', 'string', [exports.magic_t_ptr, 'int']), | ||
magic_buffer: sharedLib.func('magic_buffer', 'string', [exports.magic_t_ptr, 'void*', 'size_t']), | ||
magic_error: sharedLib.func('magic_error', 'string', [exports.magic_t_ptr]), | ||
magic_getflags: sharedLib.func('magic_getflags', 'int', [exports.magic_t_ptr]), | ||
magic_setflags: sharedLib.func('magic_setflags', 'int', [exports.magic_t_ptr, 'int']), | ||
magic_version: sharedLib.func('magic_version', 'int', []), | ||
magic_load: sharedLib.func('magic_load', 'int', [exports.magic_t_ptr, 'string']), | ||
magic_load_buffers: sharedLib.func('magic_load_buffers', 'int', [exports.magic_t_ptr, 'void**', 'size_t*', 'size_t']), | ||
magic_compile: sharedLib.func('magic_compile', 'int', [exports.magic_t_ptr, 'string']), | ||
magic_check: sharedLib.func('magic_check', 'int', [exports.magic_t_ptr, 'string']), | ||
magic_list: sharedLib.func('magic_list', 'int', [exports.magic_t_ptr, 'string']), | ||
magic_errno: sharedLib.func('magic_errno', 'int', [exports.magic_t_ptr]), | ||
magic_setparam: sharedLib.func('magic_setparam', 'int', [exports.magic_t_ptr, 'int', 'void*']), | ||
magic_getparam: sharedLib.func('magic_getparam', 'int', [exports.magic_t_ptr, 'int', 'void*']), | ||
}; | ||
exports.default = exports.libmagic; | ||
//# sourceMappingURL=libmagic.js.map |
/// <reference types="node" /> | ||
import type { Pointer } from 'ref-napi'; | ||
import pool from 'generic-pool'; | ||
@@ -41,3 +40,3 @@ declare function getConfigObj(): { | ||
export declare class LibmagicIO { | ||
pool: pool.Pool<Pointer<void>>; | ||
pool: pool.Pool<unknown>; | ||
config: ReturnType<typeof getConfigObj> & { | ||
@@ -44,0 +43,0 @@ magicDBPath?: string; |
@@ -79,3 +79,2 @@ "use strict"; | ||
const handle = await pMagicOpen(this.config.flag); | ||
handle._flag = this.config.flag; | ||
const r = await pMagicLoad(handle, this.config.magicDBPath || null); | ||
@@ -85,3 +84,2 @@ if (r === -1) { | ||
} | ||
handle._dbPath = this.config.magicDBPath; | ||
return handle; | ||
@@ -92,18 +90,6 @@ }, | ||
}, | ||
validate: async (handle) => { | ||
if (handle._flag !== this.config.flag) { | ||
return false; | ||
} | ||
if (handle._dbPath !== this.config.magicDBPath) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}, { ...this.config.pool, testOnBorrow: true }); | ||
}, { ...this.config.pool }); | ||
} | ||
async getLibmagicVersion() { | ||
return this.pool.use(async () => { | ||
const r = await pMagicVersion(); | ||
return r; | ||
}); | ||
getLibmagicVersion() { | ||
return pMagicVersion(); | ||
} | ||
@@ -110,0 +96,0 @@ async close() { |
{ | ||
"name": "libmagic-ffi", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Node bindings for libmagic using ffi", | ||
@@ -16,11 +16,8 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"ffi-napi": "^4.0.3", | ||
"generic-pool": "^3.8.2", | ||
"ref-napi": "^3.0.3", | ||
"generic-pool": "^3.9.0", | ||
"koffi": "^2.8.0", | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/ffi-napi": "^4.0.5", | ||
"@types/jest": "^28.1.6", | ||
"@types/ref-napi": "^3.0.4", | ||
"jest": "^28.1.3", | ||
@@ -27,0 +24,0 @@ "ts-jest": "^28.0.7", |
# node-libmagic-ffi | ||
Node binding for libmagic using `node-ffi-napi` | ||
Node binding for libmagic using `koffi` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
5
23934
388
+ Addedkoffi@^2.8.0
+ Addedkoffi@2.9.2(transitive)
- Removedffi-napi@^4.0.3
- Removedref-napi@^3.0.3
- Removeddebug@3.2.74.3.7(transitive)
- Removedffi-napi@4.0.3(transitive)
- Removedget-symbol-from-current-process-h@1.0.2(transitive)
- Removedget-uv-event-loop-napi-h@1.0.6(transitive)
- Removedms@2.1.3(transitive)
- Removednode-addon-api@3.2.1(transitive)
- Removednode-gyp-build@4.8.4(transitive)
- Removedref-napi@3.0.3(transitive)
- Removedref-struct-di@1.1.1(transitive)
Updatedgeneric-pool@^3.9.0