Skip to content

Latest commit

 

History

History
231 lines (134 loc) · 6.36 KB

js.md

File metadata and controls

231 lines (134 loc) · 6.36 KB

Table of Contents

MagikaNode

js/magika_node.ts:29-134

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 with yarn run bin -h.
  • Client-side: see <MAGIKA_REPO>/website/src/components/FileClassifierDemo.vue

load

js/magika_node.ts:45-58

Loads the Magika model and config from URLs.

Parameters

  • 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>

identifyStream

js/magika_node.ts:66-69

Identifies the content type from a read stream

Parameters

  • stream ReadStream A read stream
  • length 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,

identifyStreamFull

js/magika_node.ts:77-80

Identifies the content type from a read stream

Parameters

  • stream ReadStream A read stream
  • length 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.

identifyBytesFull

js/magika_node.ts:87-91

Identifies the content type of a byte array, returning all probabilities instead of just the top one.

Parameters

  • 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.

identifyBytes

js/magika_node.ts:98-101

Identifies the content type of a byte array.

Parameters

  • fileBytes any a Buffer object (a fixed-length sequence of bytes)

Returns Promise<ModelResult> A dictionary containing the top label and its score

Magika

js/magika.ts:27-123

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 with yarn run bin -h.
  • Client-side: see <MAGIKA_REPO>/website/src/components/FileClassifierDemo.vue

load

js/magika.ts:52-57

Loads the Magika model and config from URLs.

Parameters

  • 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>

identifyBytesFull

js/magika.ts:64-67

Identifies the content type of a byte array, returning all probabilities instead of just the top one.

Parameters

  • 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.

identifyBytes

js/magika.ts:74-77

Identifies the content type of a byte array.

Parameters

  • fileBytes any a Buffer object (a fixed-length sequence of bytes)

Returns Promise<ModelResult> A dictionary containing the top label and its score