Contents

Roo

File.each_byte()

Invokes the passed function for each byte of this File object’s file, passing to the function the byte (as an integer) as the first parameter. The method can take an optional second parameter as an Array object (arguments). The elements of this array will be passed to the function as additional parameters. Returns the current position of the pointer in the stream as a Number.

file.each_byte(func as Function, arguments? as Array) as Number

Parameters

  • func. A reference to a function. This function must have been defined with at least one parameter as the current byte will be passed to it. This function may have additional parameters defined and these will be passed to it as the contents of the optional arguments array
  • arguments. Optional Array object. Each element of this array will be passed to func as additional parameters after the current byte

Returns

Returns the position of the pointer in the stream (file.pos)

Example

function list(byte) {
    print(byte)
}

function prefix(byte, what) {
    print(what + byte)
}

# Assume file contents are:
# Iron Man
# Hulk
# Thor

var f = File("/Users/garry/Desktop/test.txt")
f.each_byte(list)
# Prints:
# 73
# 114
# 111, etc

f.each_byte(prefix, ["Byte Value: "])
# Prints:
# Byte Value: 73
# Byte Value: 114
# Byte Value: 111, etc