lswbxml
Fast streaming WBXML parser and generator for Node.js.
Installation
With npm:
npm install lswbxml
Parsing WBXML
LiveScript:
require! fswbxml = require \lswbxml # With streamsfile = fs.create-read-stream 'example.wbxml'<-! file.on \openwbxml.decode file, language: \ActiveSync, !(err, obj)-> throw err if err console.log 'Parsed WBXML:' console.log obj # With buffers (synchronous)buf = fs.read-file-sync 'example.wbxml'obj = wbxml.decode-sync buf, language: \ActiveSyncconsole.log 'Parsed WBXML:'console.log obj
CoffeeScript:
fs = require 'fs'wbxml = require 'lswbxml' # With streamsfile = fs.createReadStream 'example.wbxml'file.on 'open', -> wbxml.decode file, language: 'ActiveSync', (err, obj)-> throw err if err console.log 'Parsed WBXML:' console.log obj # With buffers (synchronous)buf = fs.readFileSync 'example.wbxml'obj = wbxml.decodeSync buf, language: 'ActiveSync'console.log 'Parsed WBXML:'console.log obj
JavaScript
fs = ;wbxml = ; // With streamsfile = fs;file; // With buffers (synchronous)buf = fs;obj = wbxml;console;console;
Parsing WBXML stream
LiveScript:
require! fswbxml = require \lswbxml file = fs.create-read-stream 'example.wbxml'<-! file.on \openobj = nulldecoder = new wbxml.Decoder language: \ActiveSync ..on \error !-> throw it ..on \readable !-> obj := decoder.read! ..on \end !-> throw Error("Incomplete WBXML stream") if not obj? console.log 'Parsed WBXML:' console.log objfile.pipe decoder
CoffeeScript:
fs = require 'fs'wbxml = require 'lswbxml' file = fs.createReadStream 'example.wbxml'file.on 'open', -> obj = null decoder = new wbxml.Decoder language: 'ActiveSync' decoder.on 'error', (err)-> throw err decoder.on 'readable', -> obj = decoder.read() decoder.on 'end', -> throw Error("Incomplete WBXML stream") if obj is null console.log 'Parsed WBXML:' console.log obj file.pipe decoder
JavaScript:
fs = ;wbxml = ; file = fs;file;
Building from source
Install gulp with:
npm install -g gulp
And run:
gulp build
or:
gulp watch
for continuous integration.
Testing
Run:
gulp test