npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ebml

v3.0.0

Published

ebml parser

Downloads

54,225

Readme

EBML Build Status NPM Coverage Status Greenkeeper badge

EBML stands for Extensible Binary Meta-Language and is somewhat of a binary version of XML. It's used for container formats like WebM or MKV.

Note

This is for version 3.0.0 and up, which has undergone a massive rewrite and now builds with RollupJS.

Version 2.2.4 is the last version to have guaranteed legacy semantics.

Install

Install via NPM or Yarn:

npm install ebml --save
# or
yarn add ebml

Usage

The Decoder() class is implemented as a Node Transform stream. As input it takes EBML. As output it emits a sequence of chunks: two-element arrays looking like this example.

[ "tag",
  {
    name: "TimecodeScale",
    type: "u",
    value: 1000000
   }
 ]

The first element of the array is a short text string. For tags containing values, like this example, the string is 'tag'. ebml also has nesting tags. The opening of those tags has the string 'start' and the closing has the string 'end'. Integers stored in 6 bytes or less are represented as numbers, and longer integers are represented as hexadecimal text strings.

The second element of the array is an object with these members, among others:

  • name is the Matroska Element Name.
  • type is the data type.
    • u: unsigned integer. Some of these are UIDs, coded as 128-bit numbers.
    • i: signed integer.
    • f: IEEE-754 floating point number.
    • s: printable ASCII text string.
    • 8: printable utf-8 Unicode text string.
    • d: a 64-bit signed timestamp, in nanoseconds after (or before) 2001-01-01T00:00UTC.
    • b binary data, otherwise uninterpreted.
  • value is the value of the data in the element, represented as a number or a string.
  • data is the binary data of the entire element stored in a Uint8Array.

Elements with the Block and SimpleBlock types get special treatment. They have these additional members:

  • payload is the coded information in the element, stored in a Uint8Array.
  • track is an unsigned integer indicating the payload's track.
  • keyframe is a Boolean value set to true if the payload starts an I frame (SimpleBlocks only).
  • discardable is a Boolean value showing the value of the element's Discardable flag. (SimpleBlocks only).

And the value member shows the block's Timecode value.

Examples

This example reads a media file into memory and decodes it. The decoder invokes its data event for each Element.

const fs = require('fs');
const { Decoder } = require('./lib/ebml.js');

const decoder = new Decoder();

decoder.on('data', chunk => console.log(chunk));

fs.readFile('media/test.webm', (err, data) => {
    if (err) {
        throw err;
    }
    decoder.write(data);
});

This example does the same thing, but by piping the file stream into the decoder (a Transform stream).

const { Decoder } = require('./lib/ebml.js');

const ebmlDecoder = new Decoder();
const counts = {};

require('fs')
    .createReadStream('media/test.webm')
    .pipe(ebmlDecoder)
    .on('data', chunk => {
        const { name } = chunk[1];
        if (!counts[name]) {
            counts[name] = 0;
        }
        counts[name] += 1;
    })
    .on('finish', () => console.log(counts));

State of this project

Parsing should work. If it doesn't, please create an issue.

d-type elements (timestamps) are not yet decoded to Javascript timestamp values.

Thanks to @chrisprice we got an encoder!

License

MIT

Contributors

(in alphabetical order)