The blob library implements binary data manipulations routines. The library is based on blob objects that rapresent a buffer of arbitrary binary data.
blob(
size)
;
returns a new instance of a blob class of the specified size in bytes
castf2i(
f)
;
casts a float to a int
casti2f(
n)
;
casts a int to a float
swap2(
n)
;
swap the byte order of a number (like it would be a 16bits integer)
swap4(
n)
;
swap the byte order of an integer
swapfloat(
f)
;
swaps the byteorder of a float
The blob object is a buffer of arbitrary binary data. The object behaves like
a file stream, it has a read/write pointer and it automatically grows if data
is written out of his boundary.
A blob can also be accessed byte by byte through the [] operator.
eos(
)
;
returns a non null value if the read/write pointer is at the end of the stream.
flush(
)
;
flushes the stream.return a value != null if succeded, otherwise returns null
len(
)
;
returns the lenght of the stream
readblob(
size)
;
read n bytes from the stream and retuns them as blob
readn(
type)
;
reads a number from the stream according to the type pameter. type can have the following values:
'l' | processor dependent, 32bits on 32bits processors, 64bits on 64bits prcessors | returns an integer |
'i' | 32bits number | returns an integer |
's' | 16bits signed integer | returns an integer |
'w' | 16bits unsigned integer | returns an integer |
'c' | 8bits signed integer | returns an integer |
'b' | 8bits unsigned integer | returns an integer |
'f' | 32bits float | returns an float |
'd' | 64bits float | returns an float |
resize(
size)
;
resizes the blob to the specified size
seek(
seek, [origin])
;
Moves the read/write pointer to a specified location. offset indicates the number of bytes from origin. origin can be 'b' beginning of the stream,'c' current location or 'e' end of the stream. If origin is omitted the parameter is defaulted as 'b'(beginning of the stream).
swap2(
)
;
swaps the byte order of the blob content as it would be an array of 16bits integers
swap4(
)
;
swaps the byte order of the blob content as it would be an array of 32bits integers
tell(
)
;
returns read/write pointer absolute position
writeblob(
blob)
;
writes a blob in the stream
writen(
n, type)
;
writes a number in the stream formatted according to the type pameter. type can have the following values:
'i' | 32bits number |
's' | 16bits signed integer |
'w' | 16bits unsigned integer |
'c' | 8bits signed integer |
'b' | 8bits unsigned integer |
'f' | 32bits float |
'd' | 64bits float |