Package Exports
- avsc
- avsc/lib/types
- avsc/lib/utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (avsc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Avsc

Pure JavaScript implementation of the Avro specification.
Features
- Arbitrary Avro schema support, and schema evolution.
- No dependencies.
- Fast! Did you know that Avro could be faster than JSON?
Installation
$ npm install avscavsc is compatible with io.js and versions of node.js from and
including 0.11.
Documentation
A few examples to boot:
Encode and decode JavaScript objects using an Avro schema file:
var avsc = require('avsc'); // Implied in all other examples below. var type = avsc.parse('Person.avsc'); var buf = type.encode({name: 'Ann', age: 25}); // Serialize a JS object. var obj = type.decode(buf); // And deserialize it back.
Get a readable record stream from an Avro container file:
avsc.decodeFile('records.avro') .on('data', function (record) { /* Do something with the record. */ });
Generate a random instance from a schema object:
var type = avsc.parse({ name: 'Pet', type: 'record', fields: [ {name: 'kind', type: {name: 'Kind', type: 'enum', symbols: ['CAT', 'DOG']}}, {name: 'name', type: 'string'}, {name: 'isFurry', type: 'boolean'} ] }); var pet = type.random(); // E.g. {kind: 'CAT', name: 'qwXlrew', isFurry: true}
Create a duplex stream to serialize objects on the fly:
var type = avsc.parse({type: 'array', items: 'int'}); var encoder = new avsc.streams.RawEncoder(type) .on('data', function (chunk) { /* Do something with the chunk. */ }); encoder.write([123, 5]); encoder.end([10]);
Performance
Despite being written in pure JavaScript, avsc is still fast: supporting
encoding and decoding throughput rates in the 100,000s per second for complex
schemas.
| Schema | Decode (operations/sec) | Encode (operations/sec) |
|---|---|---|
ArrayString.avsc |
905k | 280k |
Coupon.avsc |
290k | 302k |
Person.avsc |
1586k | 620k |
User.avsc |
116k | 284k |
In fact, it is generally faster than the built-in JSON parser (also producing encodings orders of magnitude smaller without compression). See the benchmarks page for the raw numbers.
Limitations
- Protocols aren't yet implemented.
- JavaScript doesn't natively support the
longtype, so numbers larger thanNumber.MAX_SAFE_INTEGER(or smaller than the corresponding lower bound) might suffer a loss of precision.