Extends Magika
The main Magika object for Node use.
Example usage:
import { readFile } from "fs/promises";
import { MagikaNode as Magika } from "magika";
const data = await readFile("some file");
const magika = new Magika();
await magika.load();
const prediction = await magika.identifyBytes(data);
console.log(prediction);
For a client-side implementation, please import Magika
instead.
Demos:
- Node:
<MAGIKA_REPO>/js/index.js
, which you can run withyarn run bin -h
. - Client-side: see
<MAGIKA_REPO>/website/src/components/FileClassifierDemo.vue
Loads the Magika model and config from URLs.
options
MagikaOptions The urls or file paths where the model and its config are stored.Parameters are optional. If not provided, the model will be loaded from GitHub.
Returns Promise<void>
Identifies the content type from a read stream
stream
ReadStream A read streamlength
number Total length of stream data (this is needed to find the middle without keep the file in memory)
Returns Promise<ModelResult> A dictionary containing the top label and its score,
Identifies the content type from a read stream
stream
ReadStream A read streamlength
number Total length of stream data (this is needed to find the middle without keep the file in memory)
Returns Promise<ModelResultLabels> A dictionary containing the top label, its score, and a list of content types and their scores.
Identifies the content type of a byte array, returning all probabilities instead of just the top one.
fileBytes
any a Buffer object (a fixed-length sequence of bytes)
Returns Promise<ModelResultLabels> A dictionary containing the top label, its score, and a list of content types and their scores.
Identifies the content type of a byte array.
fileBytes
any a Buffer object (a fixed-length sequence of bytes)
Returns Promise<ModelResult> A dictionary containing the top label and its score
The main Magika object for client-side use.
Example usage:
const file = new File(["# Hello I am a markdown file"], "hello.md");
const fileBytes = new Uint8Array(await file.arrayBuffer());
const magika = new Magika();
await magika.load();
const prediction = await magika.identifyBytes(fileBytes);
console.log(prediction);
For a Node implementation, please import MagikaNode
instead.
Demos:
- Node:
<MAGIKA_REPO>/js/index.js
, which you can run withyarn run bin -h
. - Client-side: see
<MAGIKA_REPO>/website/src/components/FileClassifierDemo.vue
Loads the Magika model and config from URLs.
options
MagikaOptions The urls where the model and its config are stored.Parameters are optional. If not provided, the model will be loaded from GitHub.
Returns Promise<void>
Identifies the content type of a byte array, returning all probabilities instead of just the top one.
fileBytes
any a Buffer object (a fixed-length sequence of bytes)
Returns Promise<ModelResultLabels> A dictionary containing the top label, its score, and a list of content types and their scores.
Identifies the content type of a byte array.
fileBytes
any a Buffer object (a fixed-length sequence of bytes)
Returns Promise<ModelResult> A dictionary containing the top label and its score