hummus-recipe
Version:
A powerful PDF tool for NodeJS based on HummusJS
59 lines (43 loc) • 1.32 kB
text/coffeescript
ArrayT = require './Array'
{Number:NumberT} = require './Number'
utils = require './utils'
{inspect} = require 'util'
class LazyArrayT extends ArrayT
decode: (stream, parent) ->
pos = stream.pos
length = utils.resolveLength , stream, parent
if instanceof NumberT
parent =
parent: parent
_startOffset: pos
_currentOffset: 0
_length: length
res = new LazyArray , length, stream, parent
stream.pos += length * .size(null, parent)
return res
size: (val, ctx) ->
if val instanceof LazyArray
val = val.toArray()
super val, ctx
encode: (stream, val, ctx) ->
if val instanceof LazyArray
val = val.toArray()
super stream, val, ctx
class LazyArray
constructor: (, , , ) ->
= .pos
= []
get: (index) ->
if index < 0 or index >=
return undefined
unless [index]?
pos = .pos
.pos = + .size(null, ) * index
[index] = .decode ,
.pos = pos
return [index]
toArray: ->
for i in [0...] by 1
inspect: ->
inspect
module.exports = LazyArrayT