Win32Forth


Classes for File I/O


File I/O class

:Class File     <Super Object

File I/O class

:M Close:       ( -- )

Close the file.

:M Open:        ( -- f )

Open the file

:M Read:        { addr cnt -- f }

Read cnt bytes from the file into memory

:M Write:       { addr cnt -- f }

Write cnt bytes from memory into the file.

:M Create:      ( -- f )

Create the file.

:M Delete:      ( -- )

Delete the file

:M Rename:      { addr cnt -- }

Rename the file.

:M GetPosition: ( -- ud )

Get the position of the file pointer

:M RePosition:  ( ud -- )

Set the position of the file pointer

:M FileSize:    ( -- ud )

Get the size of the file

:M Append:      ( -- )

Set append mode

:M Flush:       ( -- )

Flush the file

:M ReadLine:    ( addr len -- len eof )

Read a line from the file.

:M WriteLine:   ( addr len -- )

Write a line to the file

:M Resize:      ( ud -- )

Resize the file

:M Exist?:      ( -- f )

Check if the file exist

:M SetName:     ( addr cnt -- )

Set the file name

:M GetName:     ( -- addr )

Get the file name

:M ClearName:   ( -- )

Clear the file name

:M SetMode:     ( mode -- )

Set the I/O mode

:M ErrorCode:   ( -- n )

Get the error code of the previous file I/O

;Class

End of File class

Class for loading/saving a complete file from/to memory

:Class ReadFile <Super File

ReadFile class for loading/saving a complete file from/to memory.

:M ReleaseBuffer: ( -- )

Free the memory of the file-buffer

:M GetBuffer:   ( -- addr len )

Fet the address and len of the file-buffer

:M GetLength:   ( -- len )

Get the length of the file-buffer

:M SetLength:   ( len -- )

Set the length of the file-buffer.

NOTE: with this method you can set the length behind the allocated memory of the file-buffer! So take care.

:M SetBuffer:   ( addr len -- )

Set the address and length of the file-buffer

:M AllocBuffer: ( len -- )

Allocate memory for the file-buffer

:M LoadFile:    ( addr len -- f )

load a file into the file-buffer, f=true on success

:M SaveFile:    ( -- )

Save the file-buffer to the file

;Class

End of ReadFile class

Example

ReadFile MyDumpFile

: DumpFile  ( addr len -- )

        \ Load the file into memory
        LoadFile: MyDumpFile
        if   \ get the address and length of the file buffer
             GetBuffer: MyDumpFile ( addr len )

             \ do something with the file data
             dump

             \ don't forget to close the file
             Close: MyDumpFile
        else abort" Can't read file."
        then ;

s" temp.f" DumpFile


Document $Id: File.htm,v 1.10 2007/05/26 10:24:12 dbu_de Exp $