Skip to main content

Load from bytes

You already have the bytes β€” from a fetch with auth headers, a <input type="file"> upload, an IndexedDB cache, or a Node.js readFile on the server. Hand the buffer to api.load() and skip the built-in fetcher entirely.

Fetching bytes…

When the bytes come from you​

Any pipeline that already has the file in memory belongs here:

  • Node.js and server-side rendering β€” fs.readFileSync produces a Buffer.
  • Backends that stream from S3, a database blob column, or an internal API.
  • Browser code that fetched the file with a custom fetch (auth headers, retries, progress reporting).
  • Desktop and mobile hosts that read from the local filesystem or a content provider.

api.load() accepts a Uint8Array or an ArrayBuffer on every runtime. alphaTab probes the leading bytes to pick an importer β€” Guitar Pro, MusicXML, Capella, or alphaTex β€” so you do not tell it what format you handed over.

Pair it with track selection​

The second argument to api.load() picks which tracks render on arrival. Pass [0] to open a multi-track file on the first track only, or [0, 2, 5] to render a subset. Omitting the argument uses whatever core.tracks was set to at construction time.

Show it in code​

import * as alphaTab from '@coderline/alphatab';

const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
// No core.file here β€” the bytes arrive after construction.
});

const bytes = await readScoreFile('song.gp');
api.load(bytes, [0]);

api.scoreLoaded.on((score) => {
console.log(`Loaded ${score.title}, ${score.tracks.length} tracks total`);
});

getAlphaTabContainer() is a placeholder for the platform-specific step of obtaining the render target. readScoreFile() is a placeholder for the platform-specific step of producing a Uint8Array β€” fs.promises.readFile on Node.js, System.IO.File.ReadAllBytes on .NET, ContentResolver.openInputStream on Android, or fetch(...).then(r => r.arrayBuffer()) in the browser.

Where to look next​