sopen
var sopen(var self, var resource, var options);
Open the stream self with a given resource and options.
sclose
void sclose(var self);
Close the stream self.
sseek
void sseek(var self, int64_t pos, int origin);
Seek to the position pos from some origin in the stream self.
stell
int64_t stell(var self);
Return the current position of the stream stell.
sflush
void sflush(var self);
Flush the buffered contents of stream self.
seof
bool seof(var self);
Returns true if there is no more information in the stream.
sread
size_t sread(var self, void* output, size_t size);
Read size bytes from the stream self and write them to output.
swrite
size_t swrite(var self, void* input, size_t size);
Write size bytes to the stream self and read them from input.
Usage
var f = sopen($(File, NULL), $S("test.bin"), $S("r"));
char c;
while (!seof(f)) {
sread(f, &c, 1);
putc(c, stdout);
}
sclose(f);
File-like
The Stream class represents an abstract set of operations that can be performed on File-like objects.
struct Stream {
var (*sopen)(var,var,var);
void (*sclose)(var);
void (*sseek)(var,int64_t,int);
int64_t (*stell)(var);
void (*sflush)(var);
bool (*seof)(var);
size_t (*sread)(var,void*,size_t);
size_t (*swrite)(var,void*,size_t);
};