Checks if the the cursor position is after the last character of the file referenced in the TextStream object.
var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
// Is end of file reached ?
while( !myStream.end() ){
console.log( myStream.read( 10 ) );
}
// Important to close the stream every time.
myStream.close();
true
if the cursor position is at the end of file, false
otherwise.
Saves the contents of the TextStream buffer to the disk file.
Get the current cursor position in the text stream.
var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
while( !myStream.end() ){
myStream.read( 10 );
console.log( myStream.getPos() );
// 10, 20, 30, ...
}
// Important to close the stream every time.
myStream.close();
Get the current text stream size.
var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
console.log( myStream.getSize() );
// 183
// Important to close the stream every time.
myStream.close();
Reads bytes from the text stream.
var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
while( !myStream.end() ){
// Read the next 10 bytes and moves the cursor position accordingly
console.log( myStream.read( 10 ) );
}
// Important to close the stream every time.
myStream.close();
(default: TextStream.getSize()
) Number of bytes to read
Set the cursor position to the beginning of the TextStream.
var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
console.log( 'Start: '+ myStream.getPos() );
myStream.read(20);
console.log( 'After read: '+ myStream.getPos() );
myStream.rewind();
console.log( 'After rewind: '+ myStream.getPos() );
// Important to close the stream every time.
myStream.close();
Writes the text in the TextStream.
var myFile = new File( 'PROJECT/my-streamed-file.js' );
var myStream = new TextStream( file, 'write' );
myStream.write( 'Hello '+ Date.now() +' !\n' );
// Important to close the stream every time.
myStream.close();
String to write in the TextStream
Closes the file referenced in the TextStream object.
var myFile = new File( 'PROJECT/my-streamed-file.js' ); var myStream = new TextStream( file, 'write' ); myStream.write( 'Hello '+ Date.now() +' !\n' ); // Important to close the stream every time. myStream.close();