Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface WAKTextStreamInstance

Hierarchy

  • WAKTextStreamInstance

Index

Methods

close

  • close(): void
  • 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();

    Returns void

end

  • end(): Boolean
  • 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();

    Returns Boolean

    true if the cursor position is at the end of file, false otherwise.

flush

  • flush(): void
  • Saves the contents of the TextStream buffer to the disk file.

    Returns void

getPos

  • getPos(): Number
  • 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();

    Returns Number

getSize

  • getSize(): Number
  • 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();

    Returns Number

read

  • read(nbBytes?: Number): String
  • 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();

    Parameters

    • Optional nbBytes: Number

      (default: TextStream.getSize()) Number of bytes to read

    Returns String

rewind

  • rewind(): void
  • 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();

    Returns void

write

  • write(text: String): void
  • 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();

    Parameters

    • text: String

      String to write in the TextStream

    Returns void