avsc
Avro for JavaScript
Last updated 7 years ago by mtth .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install avsc 
SYNC missed versions from official npm registry.

Avsc NPM version Download count Build status Coverage status

Pure JavaScript implementation of the Avro specification.

Features

Installation

$ npm install avsc

avsc is compatible with all versions of node.js since 0.11 and major browsers via browserify (see the full compatibility table here). For convenience, you can also find compiled distributions with the releases (but please host your own copy).

Documentation

Examples

Inside a node.js module, or using browserify:

const avro = require('avsc');
  • Encode and decode values from a known schema:

    const type = avro.Type.forSchema({
      type: 'record',
      fields: [
        {name: 'kind', type: {type: 'enum', symbols: ['CAT', 'DOG']}},
        {name: 'name', type: 'string'}
      ]
    });
    
    const buf = type.toBuffer({kind: 'CAT', name: 'Albert'}); // Encoded buffer.
    const val = type.fromBuffer(buf); // = {kind: 'CAT', name: 'Albert'}
    
  • Infer a value's schema and encode similar values:

    const type = avro.Type.forValue({
      city: 'Cambridge',
      zipCodes: ['02138', '02139'],
      visits: 2
    });
    
    // We can use `type` to encode any values with the same structure:
    const bufs = [
      type.toBuffer({city: 'Seattle', zipCodes: ['98101'], visits: 3}),
      type.toBuffer({city: 'NYC', zipCodes: [], visits: 0})
    ];
    
  • Get a readable stream of decoded values from an Avro container file compressed using Snappy (see the BlockDecoder API for an example including checksum validation):

    const snappy = require('snappy'); // Or your favorite Snappy library.
    const codecs = {
      snappy: function (buf, cb) {
        // Avro appends checksums to compressed blocks, which we skip here.
        return snappy.uncompress(buf.slice(0, buf.length - 4), cb);
      }
    };
    
    avro.createFileDecoder('./values.avro', {codecs})
      .on('metadata', function (type) { /* `type` is the writer's type. */ })
      .on('data', function (val) { /* Do something with the decoded value. */ });
    
  • Implement a TCP server for an IDL-defined protocol:

    // We first generate a protocol from its IDL specification.
    const protocol = avro.readProtocol(`
      protocol LengthService {
        /** Endpoint which returns the length of the input string. */
        int stringLength(string str);
      }
    `);
    
    // We then create a corresponding server, implementing our endpoint.
    const server = avro.Service.forProtocol(protocol)
      .createServer()
      .onStringLength(function (str, cb) { cb(null, str.length); });
    
    // Finally, we use our server to respond to incoming TCP connections!
    require('net').createServer()
      .on('connection', (con) => { server.createChannel(con); })
      .listen(24950);
    

Current Tags

  • 6.0.0-alpha.13                                ...           alpha (6 years ago)
  • 5.7.7                                ...           latest (2 years ago)

155 Versions

  • 5.7.7                                ...           2 years ago
  • 5.7.6                                ...           2 years ago
  • 5.7.5                                ...           2 years ago
  • 5.7.4                                ...           3 years ago
  • 5.7.3                                ...           3 years ago
  • 5.7.2                                ...           3 years ago
  • 5.7.1                                ...           3 years ago
  • 5.7.0                                ...           4 years ago
  • 5.6.3                                ...           4 years ago
  • 5.6.2                                ...           4 years ago
  • 5.6.1                                ...           4 years ago
  • 5.6.0                                ...           4 years ago
  • 5.5.3                                ...           4 years ago
  • 5.5.2                                ...           4 years ago
  • 5.5.1                                ...           4 years ago
  • 5.5.0                                ...           4 years ago
  • 5.4.22                                ...           4 years ago
  • 5.4.21                                ...           5 years ago
  • 5.4.20                                ...           5 years ago
  • 5.4.19                                ...           5 years ago
  • 5.4.18                                ...           5 years ago
  • 5.4.17                                ...           5 years ago
  • 5.4.16                                ...           5 years ago
  • 5.4.15                                ...           5 years ago
  • 5.4.14                                ...           5 years ago
  • 5.4.13                                ...           5 years ago
  • 5.4.12                                ...           5 years ago
  • 5.4.11                                ...           5 years ago
  • 5.4.10                                ...           6 years ago
  • 5.4.9                                ...           6 years ago
  • 6.0.0-alpha.13                                ...           6 years ago
  • 6.0.0-alpha.12                                ...           6 years ago
  • 5.4.7                                ...           6 years ago
  • 5.4.6                                ...           6 years ago
  • 5.4.5                                ...           6 years ago
  • 5.4.4                                ...           6 years ago
  • 5.4.3                                ...           6 years ago
  • 5.4.2                                ...           6 years ago
  • 6.0.0-alpha.11                                ...           6 years ago
  • 5.4.1                                ...           6 years ago
  • 5.4.0                                ...           6 years ago
  • 5.3.1                                ...           6 years ago
  • 5.3.0                                ...           6 years ago
  • 5.2.4                                ...           6 years ago
  • 5.2.3                                ...           7 years ago
  • 5.2.2                                ...           7 years ago
  • 6.0.0-alpha.10                                ...           7 years ago
  • 5.2.1                                ...           7 years ago
  • 6.0.0-alpha.9                                ...           7 years ago
  • 5.2.0                                ...           7 years ago
  • 5.1.2                                ...           7 years ago
  • 5.1.1                                ...           7 years ago
  • 5.1.0                                ...           7 years ago
  • 6.0.0-alpha.8                                ...           7 years ago
  • 6.0.0-alpha.7                                ...           7 years ago
  • 6.0.0-alpha.6                                ...           7 years ago
  • 6.0.0-alpha.5                                ...           7 years ago
  • 6.0.0-alpha.4                                ...           7 years ago
  • 5.0.7                                ...           7 years ago
  • 6.0.0-alpha.3                                ...           7 years ago
  • 6.0.0-alpha.1                                ...           7 years ago
  • 5.0.6                                ...           7 years ago
  • 5.0.5                                ...           7 years ago
  • 5.0.4                                ...           7 years ago
  • 5.0.3                                ...           7 years ago
  • 5.0.2                                ...           8 years ago
  • 5.0.1                                ...           8 years ago
  • 5.0.0                                ...           8 years ago
  • 5.0.0-rc.24                                ...           8 years ago
  • 5.0.0-rc.23                                ...           8 years ago
  • 5.0.0-rc.22                                ...           8 years ago
  • 5.0.0-rc.21                                ...           8 years ago
  • 5.0.0-rc.20                                ...           8 years ago
  • 5.0.0-rc.19                                ...           8 years ago
  • 5.0.0-rc19                                ...           8 years ago
  • 5.0.0-rc.18                                ...           8 years ago
  • 5.0.0-rc.17                                ...           8 years ago
  • 5.0.0-rc.16                                ...           8 years ago
  • 5.0.0-rc.15                                ...           8 years ago
  • 5.0.0-rc.14                                ...           8 years ago
  • 5.0.0-rc.13                                ...           8 years ago
  • 5.0.0-rc.12                                ...           8 years ago
  • 5.0.0-rc.11                                ...           8 years ago
  • 5.0.0-rc.10                                ...           8 years ago
  • 5.0.0-rc.9                                ...           8 years ago
  • 5.0.0-rc.8                                ...           8 years ago
  • 5.0.0-rc.7                                ...           8 years ago
  • 5.0.0-rc.6                                ...           8 years ago
  • 5.0.0-rc.5                                ...           8 years ago
  • 5.0.0-rc.4                                ...           8 years ago
  • 5.0.0-rc.3                                ...           8 years ago
  • 4.1.11                                ...           8 years ago
  • 4.1.10                                ...           8 years ago
  • 4.1.9                                ...           8 years ago
  • 4.1.8                                ...           8 years ago
  • 4.1.7                                ...           8 years ago
  • 4.1.6                                ...           8 years ago
  • 4.1.5                                ...           8 years ago
  • 4.1.4                                ...           8 years ago
  • 4.1.3                                ...           8 years ago
  • 4.1.2                                ...           8 years ago
  • 4.1.1                                ...           8 years ago
  • 4.1.0                                ...           9 years ago
  • 4.0.1                                ...           9 years ago
  • 4.0.0                                ...           9 years ago
  • 3.4.2                                ...           9 years ago
  • 3.4.1                                ...           9 years ago
  • 3.4.0                                ...           9 years ago
  • 3.3.11                                ...           9 years ago
  • 3.3.10                                ...           9 years ago
  • 3.3.9                                ...           9 years ago
  • 3.3.8                                ...           9 years ago
  • 3.3.7                                ...           9 years ago
  • 3.3.6                                ...           9 years ago
  • 3.3.5                                ...           9 years ago
  • 3.3.4                                ...           9 years ago
  • 3.3.3                                ...           9 years ago
  • 3.3.2                                ...           9 years ago
  • 3.3.1                                ...           9 years ago
  • 3.3.0                                ...           9 years ago
  • 3.2.2                                ...           9 years ago
  • 3.2.0                                ...           9 years ago
  • 3.1.5                                ...           9 years ago
  • 3.1.4                                ...           9 years ago
  • 3.1.3                                ...           9 years ago
  • 3.1.2                                ...           9 years ago
  • 3.1.1                                ...           9 years ago
  • 3.1.0                                ...           9 years ago
  • 3.0.2                                ...           9 years ago
  • 3.0.1                                ...           9 years ago
  • 3.0.0                                ...           9 years ago
  • 2.5.1                                ...           9 years ago
  • 2.5.0                                ...           9 years ago
  • 2.4.0                                ...           9 years ago
  • 2.3.1                                ...           9 years ago
  • 2.3.0                                ...           9 years ago
  • 2.2.1                                ...           9 years ago
  • 2.2.0                                ...           9 years ago
  • 2.1.5                                ...           9 years ago
  • 2.1.4                                ...           9 years ago
  • 2.1.3                                ...           9 years ago
  • 2.1.2                                ...           9 years ago
  • 2.1.1                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.7                                ...           9 years ago
  • 0.1.6                                ...           9 years ago
  • 0.1.3                                ...           9 years ago
  • 0.1.2                                ...           9 years ago
  • 0.1.1                                ...           9 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE