import { Target , TargetType , Cursor , OrderedIndex } from "./decompressor/common" ; import { decompressStages } from "./decompressor/stages" ; /**
 * Create an ordered index for decompression
 */ export function makeOrderedIndex ( ) { return { strings : [ ] , integers : [ ] , floats : [ ] , dates : [ ] , lpDates : [ ] , } ; } /**
 * Create a new cursor with a root target for specified drain mode
 */ function makeCursor ( drain ) { const rootTarget = { type : TargetType . SCALAR , value : void 0 } ; const stack = new Array ( 10 ) ; stack [ 0 ] = rootTarget ; return { index : 0 , rootTarget , stack , currentTarget : rootTarget , pointer : 0 , drain } ; } /**
 * Decompress data string with provided ordered index
 */ export function decompress ( data , orderedIndex ) { const cursor = makeCursor ( true ) ; decompressStages ( cursor , data , orderedIndex ) ; return cursor . rootTarget . value ; } /**
 * Decompress zipson data incrementally by providing each chunk of data in sequence
 */ export function decompressIncremental ( orderedIndex ) { const cursor = makeCursor ( false ) ; let buffer = '' ; function increment ( data ) { if ( data === null ) { cursor . drain = true ; } else if ( data . length === 0 ) { return ; } else { buffer += data ; } const cursorIndexBefore = cursor . index ; decompressStages ( cursor , buffer , orderedIndex ) ; const movedAmount = cursor . index - cursorIndexBefore ; if ( movedAmount > 0 ) { buffer = buffer . substring ( movedAmount ) ; cursor . index -= movedAmount ; } } return { increment , cursor } ; }