How to use the corrode.addExtension function in corrode

To help you get started, we’ve selected a few corrode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github screeny05 / openrw.js / packages / library / parser-bin / dir / index.js View on Github external
const Corrode = require('corrode');

const SECTOR_SIZE = 2048;
const ENTRY_SIZE = 32;

Corrode.addExtension('dir', function(){
    this
        .loop('entries', function(){
            this
                .uint32('offset')
                .uint32('size')
                .string('name', 24)
                .map.trimNull('name')
                .tap(function(){
                    this.vars.offset *= SECTOR_SIZE;
                    this.vars.size *= SECTOR_SIZE;
                    this.emit('entry', this.vars);
                });
        })

        // file-length should match the count of entries
        .tap(function(){
github screeny05 / openrw.js / src / rwscore / parser-bin / dir / index.js View on Github external
const Corrode = require('corrode');

const SECTOR_SIZE = 2048;
const ENTRY_SIZE = 32;

Corrode.addExtension('dir', function(){
    this
        .loop('entries', function(end, discard, i){
            this
                .uint32('offset')
                .uint32('size')
                .string('name', 24)
                .map.trimNull('name')
                .tap(function(){
                    this.vars.offset *= SECTOR_SIZE;
                    this.vars.size *= SECTOR_SIZE;
                    this.emit('entry', this.vars);
                });
        })

        // file-length should match the count of entries
        .tap(function(){
github screeny05 / openrw.js / src / rwscore / parser-bin / img / index.js View on Github external
const Corrode = require('corrode');

Corrode.addExtension('img', function(dir, entryName){
    if(typeof dir === 'string'){
        dir = this.varStack.peek()[dir];
    }

    const dirEntry = dir[entryName];
    if(!dirEntry){
        throw new Error(`No entry with name ${entryName} found.`);
    }


    return this
        .skip(dirEntry.offset)
        .buffer('buffer', dirEntry.size)
        .map.push('buffer');
});
github screeny05 / openrw.js / src / rwscore / parser-bin / gxt / index.js View on Github external
const Corrode = require('corrode');

require('./tkey');
require('./tdat');

Corrode.addExtension('gxt', function(){
    this
        .ext.gxtTkey('tkey')
        .ext.gxtTdat('tdat', 'tkey')
        .map.push('tdat');
});

corrode

A batteries-included library for reading binary data.

MIT
Latest version published 6 years ago

Package Health Score

45 / 100
Full package analysis

Popular corrode functions