39 lines · 1.1 KB · Text
RawDownload
//---------------------------------------------------------------------// name: read-byte.ck// desc: example of reading raw bytes from file// NOTE: file must be opened in BINARY mode for this to work//--------------------------------------------------------------------- // default filepathme.dir() + "read-byte.txt" => string filename;// look at command lineif( me.args() > 0 ) me.arg(0) => filename; // instantiateFileIO fio;// open a file (in BINARY mode)fio.open( filename, FileIO.READ | FileIO.BINARY );// ensure it's okif( !fio.good() ){    cherr <= "can't open file: " <= filename <= " for reading..."          <= IO.newline();    me.exit();} // variable to read intoint val; // loop until endwhile( fio.more() ){    // read the next byte    fio.readInt( IO.INT8 ) => val;    // optionsss ^^^^^^^ | requires chuck-1.5.0.1 or higher    // IO.INT8, IO.INT16, IO.INT32 (default to unsigned)    // IO.UINT8, IO.UINT16, IO.UINT32 (explicitly unsigned)    // IO.SINT6, IO.SINT16, IO.SINT32 (explicitly signed)     // print the value    cherr <= val <= IO.newline();}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t