To install, run:

haxelib install tink_chunk 0.2.0 

See using Haxelib in Haxelib documentation for more information.


Tinkerbell Binary Chunks

Build Status Gitter

This library provides an abstraction for readonly binary data, that can be sliced and concatenated without copying the actual payload.

abstract Chunk {
  var length(get, never):Int;    
  function concat(that:Chunk):Chunk;
  function cursor():ChunkCursor;//see below
  function iterator():Iterator;
  function slice(from:Int, to:Int):Chunk;    
  function blitTo(target:Bytes, offset:Int):Void;
  static var EMPTY(default, null):Chunk;  
  //Some implicit conversions:
  @:to function toString():String;
  @:to function toBytes():Bytes;
  @:from static private function ofBytes(b:Bytes):Chunk;
  @:from static private function ofString(s:String):Chunk;
  //A few defitions for `&` to concatenate with other chunks but also strings and bytes
  @:op(a & b) static private function catChunk(a:Chunk, b:Chunk):Chunk;    
  @:op(a & b) static private function rcatString(a:Chunk, b:String):Chunk;
  @:op(a & b) static private function lcatString(a:String, b:Chunk):Chunk;
  @:op(a & b) static private function lcatBytes(a:Bytes, b:Chunk):Chunk;
  @:op(a & b) static private function rcatBytes(a:Chunk, b:Bytes):Chunk; 

class ChunkCursor {
  var length(default, null):Int;
  var currentPos(default, null):Int;
  var currentByte(default, null):Int;
  function next():Bool;

The cursor is not unlike a normal iterator. It's API will however be expanded for seeking and other niceties. To iterate over just a part of a chunk just grab the slice you need first and then create a cursor or iterator.

8 months ago

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github