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


  • 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 the position of the pointer in the stream (file.pos)


function list(byte) {

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

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

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

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