~/bend-docscommunity

bytes.bend relies on unsafe/foreign

raw source on the hub · import gralha-bytes@0.1.0.1/bytes.bend as Bytes

Bytes, bit streams, Huffman codes, DEFLATE/zlib, checksums, base64 and percent decoding.

2 imports
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U

Types

type ByteTree source · line 10 · raw

Data

A Bytes is a persistent byte buffer: a balanced tree over a power-of-two capacity. A flat leaf is one value per index (decoders keep whole words in a Bytes, and a flat above the leaf level is a uniform run); a word leaf packs four bytes little-endian, which is how the file effect builds a tree with a quarter of the nodes and two levels fewer to descend. Each leaf carries its own reading.

type Bytes source · line 26 · raw

Data

type BitStream source · line 110 · raw

Data

type BitRead source · line 113 · raw

Data

type Huffman source · line 138 · raw

Data

type Inflate source · line 225 · raw

Data

type DeflateTrees source · line 290 · raw

Data

Definitions

def bytes.lane source · line 15 · raw

@+index:U32 -> U32

def bytes.word.get source · line 19 · raw

@+word:U32 -> @+index:U32 -> U32

def bytes.word.put source · line 22 · raw

@+word:U32 -> @+index:U32 -> @+v:U32 -> U32

def bytes.empty source · line 29 · raw

Bytes

def bytes.get source · line 52 · raw

@bytes:Bytes -> @+index:U32 -> U32

def bytes.size source · line 56 · raw

@bytes:Bytes -> U32

def bytes.set source · line 60 · raw

@+bytes:Bytes -> @+index:U32 -> @v:U32 -> Bytes

def bytes.push source · line 64 · raw

@bytes:Bytes -> @+v:U32 -> Bytes

def bytes.string source · line 73 · raw

@s:String -> @acc:Bytes -> Bytes

def bytes.slice source · line 78 · raw

@n:Nat -> @+source:Bytes -> @+start:U32 -> @target:Bytes -> Bytes

def base64.digit source · line 89 · raw

@+c:U32 -> U32

def base64.read source · line 94 · raw

@+s:String -> @+bits:U32 -> @+count:U32 -> @+out:Bytes -> Bytes

def base64 source · line 107 · raw

@s:String -> Bytes

def bits.read source · line 116 · raw

@stream:BitStream -> @+count:U32 -> BitRead

def bits.valid source · line 125 · raw

@stream:BitStream -> Bool

def bits.invalid source · line 129 · raw

@stream:BitStream -> BitStream

def bits.align source · line 133 · raw

@+stream:BitStream -> BitStream

def huff.counts source · line 160 · raw

@n:Nat -> @+lengths:Bytes -> @+index:U32 -> @+counts:Bytes -> Bytes

def huff.codes source · line 167 · raw

@n:Nat -> @+counts:Bytes -> @+length:U32 -> @codeword:U32 -> @codes:Bytes -> Bytes

def huff.build.loop source · line 174 · raw

@+n:Nat -> @+lengths:Bytes -> @+index:U32 -> @+codes:Bytes -> @+node:Huffman -> Huffman

def huff.build source · line 183 · raw

@+lengths:Bytes -> Huffman

def huff.read.next source · line 188 · raw

@read:BitRead -> @zero:Huffman -> @one:Huffman -> @next:(@_:Huffman -> @_:BitStream -> BitRead) -> BitRead

def huff.fixed.lengths source · line 200 · raw

@n:Nat -> @+index:U32 -> @out:Bytes -> Bytes

def bytes.repeat source · line 205 · raw

@n:Nat -> @+v:U32 -> @out:Bytes -> Bytes

def inflate.length.base source · line 210 · raw

@index:U32 -> U32

def inflate.length.bits source · line 213 · raw

@index:U32 -> U32

def inflate.distance.base source · line 216 · raw

@index:U32 -> U32

def inflate.distance.bits source · line 219 · raw

@index:U32 -> U32

def inflate.code.order source · line 222 · raw

@index:U32 -> U32

def inflate.copy source · line 228 · raw

@n:Nat -> @+distance:U32 -> @+out:Bytes -> Bytes

def inflate.distance.extra source · line 233 · raw

@read:BitRead -> @+length:U32 -> @+base:U32 -> @+out:Bytes -> @limit:U32 -> Inflate

def inflate.distance source · line 240 · raw

@read:BitRead -> @length:U32 -> @out:Bytes -> @limit:U32 -> Inflate

def inflate.length.extra source · line 246 · raw

@read:BitRead -> @base:U32 -> @distance:Huffman -> @out:Bytes -> @limit:U32 -> Inflate

def inflate.symbol source · line 250 · raw

@read:BitRead -> @distance:Huffman -> @+out:Bytes -> @+limit:U32 -> Inflate

def inflate.codes.next source · line 258 · raw

@+result:Inflate -> @next:(@_:BitStream -> @_:Bytes -> Inflate) -> Inflate

def inflate.codes.step source · line 262 · raw

@+read:BitRead -> @distance:Huffman -> @+out:Bytes -> @limit:U32 -> @next:(@_:BitStream -> @_:Bytes -> Inflate) -> Inflate

def inflate.stored.byte source · line 270 · raw

@read:BitRead -> @out:Bytes -> @next:(@_:BitStream -> @_:Bytes -> Inflate) -> Inflate

def inflate.stored.nlen source · line 280 · raw

@read:BitRead -> @+length:U32 -> @+out:Bytes -> @limit:U32 -> Inflate

def inflate.stored.len source · line 286 · raw

@read:BitRead -> @out:Bytes -> @limit:U32 -> Inflate

def inflate.cl.byte source · line 293 · raw

@read:BitRead -> @codes:Bytes -> @index:U32 -> @next:(@_:BitStream -> @_:Bytes -> Inflate) -> Inflate

def inflate.length.repeat source · line 303 · raw

@read:BitRead -> @+base:U32 -> @+value:U32 -> @+remaining:U32 -> @+lengths:Bytes -> Inflate

def inflate.length.code source · line 309 · raw

@read:BitRead -> @+remaining:U32 -> @+lengths:Bytes -> Inflate

def inflate.lengths.next source · line 318 · raw

@+result:Inflate -> @remaining:U32 -> @oldSize:U32 -> @next:(@_:U32 -> @_:BitStream -> @_:Bytes -> Inflate) -> Inflate

def inflate.trees source · line 327 · raw

@result:Inflate -> @+litCount:U32 -> @distCount:U32 -> DeflateTrees

def inflate.dynamic.codes source · line 333 · raw

@result:Inflate -> @+litCount:U32 -> @+distCount:U32 -> DeflateTrees

def inflate.dynamic.header source · line 337 · raw

@read:BitRead -> DeflateTrees

def inflate.dynamic source · line 344 · raw

@trees:DeflateTrees -> @out:Bytes -> @limit:U32 -> Inflate

def inflate.block source · line 348 · raw

@+kind:U32 -> @+stream:BitStream -> @+out:Bytes -> @+limit:U32 -> Inflate

def inflate.block.done source · line 353 · raw

@+result:Inflate -> @last:Bool -> @next:(@_:BitStream -> @_:Bytes -> Inflate) -> Inflate

def inflate.header source · line 357 · raw

@read:BitRead -> @out:Bytes -> @limit:U32 -> @next:(@_:BitStream -> @_:Bytes -> Inflate) -> Inflate

def checksum.adler.loop source · line 366 · raw

@n:Nat -> @+src:Bytes -> @+index:U32 -> @+a:U32 -> @b:U32 -> U32

def checksum.adler source · line 373 · raw

@+src:Bytes -> U32

def checksum.crc.word source · line 376 · raw

@n:Nat -> @+word:U32 -> U32

def checksum.crc.table source · line 381 · raw

@n:Nat -> @+index:U32 -> @out:Bytes -> Bytes

def checksum.crc.loop source · line 386 · raw

@n:Nat -> @+src:Bytes -> @+index:U32 -> @+table:Bytes -> @+crc:U32 -> U32

def zlib.result source · line 391 · raw

@result:Inflate -> @+expected:U32 -> @checksum:U32 -> Maybe<&2, Bytes>

def zlib source · line 396 · raw

@+src:Bytes -> @+expected:U32 -> Maybe<&2, Bytes>

def uri.hex.valid source · line 403 · raw

@+c:U32 -> Bool

def uri.bytes source · line 406 · raw

@+s:String -> @+out:Bytes -> Bytes

def bytes.zero source · line 418 · raw

@+size:U32 -> Bytes

def bytes.read source · line 430 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Bytes>)

Effects (foreign code)

effect bytes.read.raw source · line 426 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Bytes>)

A file's bytes, read straight into a byte tree by the effect (File.read decodes UTF-8, and building the tree in Bend from a byte string costs a cons cell per byte); Fail carries the errno and its message.

foreign: effs/bytes_read.c, effs/bytes_read.js

Unsafe

unsafe bytes.tree.get source · line 33 · raw

@bufTree:ByteTree -> @+capacity:U32 -> @+index:U32 -> U32

unsafe bytes.tree.set source · line 42 · raw

@+bufTree:ByteTree -> @+capacity:U32 -> @+index:U32 -> @+v:U32 -> ByteTree

unsafe bytes.be source · line 84 · raw

@+bytes:Bytes -> @+at:U32 -> @count:Nat -> @acc:U32 -> U32

unsafe huff.insert source · line 145 · raw

@+node:Huffman -> @+depth:Nat -> @+codeword:U32 -> @+symbol:U32 -> Huffman

unsafe huff.read source · line 193 · raw

@node:Huffman -> @+stream:BitStream -> BitRead

unsafe inflate.codes source · line 267 · raw

@+literal:Huffman -> @+distance:Huffman -> @stream:BitStream -> @out:Bytes -> @+limit:U32 -> Inflate

unsafe inflate.stored.copy source · line 275 · raw

@n:Nat -> @stream:BitStream -> @out:Bytes -> Inflate

unsafe inflate.cl source · line 298 · raw

@n:Nat -> @+index:U32 -> @stream:BitStream -> @codes:Bytes -> Inflate

unsafe inflate.lengths source · line 323 · raw

@+remaining:U32 -> @+codes:Huffman -> @+stream:BitStream -> @+lengths:Bytes -> Inflate

unsafe inflate.blocks source · line 363 · raw

@stream:BitStream -> @out:Bytes -> @+limit:U32 -> Inflate

unsafe bytes.depth source · line 415 · raw

@+size:U32 -> @+side:U32 -> @+depth:Nat -> Nat