FetchData()
Syntax
FetchData(#File, Size)Description
Load data from the file, without modifying the file pointer position. This is only useful when reading local file with #PB_File_Streaming flag.
Parameters
#File The file to use.
Return value
None.
Example
Procedure ReadCallback(Status, Filename$, File, Size)
If Status = #PB_Status_Loaded
Debug "File: " + Filename$ + " - Size read: " + Size + " bytes"
; Do something with the data
FileSeek(0, Size, #PB_Relative) ; Skip the read data and continue the streaming
If Not Eof(0)
FetchData(0, 1024) ; Read the next 1024 bytes of the file
EndIf
ElseIf Status = #PB_Status_Error
Debug "Error when loading the file: " + Filename$
EndIf
EndProcedure
Procedure OpenFileRequesterCallback()
If NextSelectedFile()
ReadFile(0, SelectedFileID(), @ReadCallback(), #PB_LocalFile | #PB_File_Streaming)
FetchData(0, 1024) ; Read the first 1024 bytes of the file
EndIf
EndProcedure
Procedure ChooseFileEvent()
OpenFileRequester("*.txt", @OpenFileRequesterCallback())
EndProcedure
OpenWindow(0, 0, 0, 300, 50, "Read file example", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose a file...")
BindGadgetEvent(0, @ChooseFileEvent())
See Also
CreateFile(), CloseFile()
Supported OS
All