R/viewFormat.R

Defines functions readFormat viewFormat

Documented in readFormat viewFormat

# User functions for creating and viewing rawFormat's

readFormat <- function(file,
                       format,
                       width=NULL, offset=0, 
                       machine="hex",
                       flatten=TRUE) {
    if (!is.memFormat(format))
        stop("Invalid format")

    fileSize <- fileSize(file)

    infile <- file(file, "rb")
    on.exit(close(infile))

    if (offset > 0)
        seek(infile, offset)

    blocks <- lapply(format, readBlock, infile)
    fileFormat <- list(blocks=blocks)
    if (flatten) {
        fileFormat$blocks <- flattenFormat(fileFormat$blocks)
        class(fileFormat) <- c("flatRawFormat", "rawFormat")
    } else {
        class(fileFormat) <- "rawFormat"
    }
    fileFormat$offset <- offset
    fileFormat$nbytes <- seek(infile) - offset
    fileFormat
}


viewFormat <- function(..., page=FALSE) {
    print(readFormat(...), page=page)
}

Try the hexView package in your browser

Any scripts or data that you put into this service are public.

hexView documentation built on May 2, 2019, 7:02 a.m.