Extends Magika
The main Magika object for Node use (MagikaNode
).
Example usage:
import { readFile } from "fs/promises";
import { MagikaNode as Magika } from "magika";
const data = await readFile("some file");
const magika = await Magika.create();
const result = await magika.identifyBytes(data);
console.log(result.prediction.output.label);
For a client-side implementation, please import Magika
instead.
Note that this MagikaNode
class extends Magika
, which means that all
public Magika
APIs (e.g., identifyBytes
) are available for MagikaNode
as well.
Demos:
- Node:
<MAGIKA_REPO>/js/magika-cli.js
, which you can run withyarn run bin -h
. - Client-side: see
<MAGIKA_REPO>/website/src/components/FileClassifierDemo.vue
Identifies the content type from a read stream
stream
ReadStream A read stream.length
number Total length of stream data.
Returns MagikaResult An object containing the result of the content type prediction.
Factory method to create a Magika instance.
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<MagikaNode>
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 = await Magika.create();
const result = await magika.identifyBytes(fileBytes);
console.log(result.prediction.output.label);
For a Node implementation, please import MagikaNode
instead.
Demos:
- Node:
<MAGIKA_REPO>/js/magika-cli.js
, which you can run withyarn run bin -h
. - Client-side: see
<MAGIKA_REPO>/website/src/components/FileClassifierDemo.vue
Identifies the content type of a byte array.
fileBytes
Uint8Array A fixed-length sequence of bytes.
Returns MagikaResult An object containing the result of the content type prediction.
Factory method to create a Magika instance.
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.