# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0.  If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.

module streams;

atom streams:ptr;

unsafe command openReadBytes( filename:str ) :streams
address mnstr_open_rstreamwrap
comment "open a file stream for reading";
unsafe command openWriteBytes( filename:str ) :streams
address mnstr_open_wstreamwrap
comment "open a file stream for writing";

unsafe command openRead( filename:str ) :streams
address mnstr_open_rastreamwrap
comment "open ascii file stream for reading";
unsafe command openWrite( filename:str ) :streams
address mnstr_open_wastreamwrap
comment "open ascii file stream for writing";

unsafe command openRead(s:streams):streams
address mnstr_stream_rstreamwrap
comment "convert an ascii stream to binary";
unsafe command openWrite(s:streams):streams
address mnstr_stream_wstreamwrap
comment "convert an ascii stream to binary";

unsafe command socketReadBytes(skt:int,name:str):streams
address mnstr_socket_rstreamwrap
comment "open a socket stream for reading";
unsafe command socketWriteBytes(skt:int,name:str):streams
address mnstr_socket_wstreamwrap
comment "open a socket stream for writing";
unsafe command socketRead(skt:int,name:str):streams
address mnstr_socket_rastreamwrap
comment "open ascii socket stream for reading";
unsafe command socketWrite(skt:int,name:str):streams
address mnstr_socket_wastreamwrap
comment "open ascii socket stream for writing";

unsafe command blocked( s:streams ) :streams
address open_block_streamwrap
comment "open a block based stream";

unsafe command writeStr( s:streams, data:str ):void
address mnstr_write_stringwrap
comment "write data on the stream";
unsafe command writeInt( s:streams, data:int ):void
address mnstr_writeIntwrap
comment "write data on the stream";
unsafe command readStr( s:streams):str
address mnstr_read_stringwrap
comment "read string data from the stream";
unsafe command readInt( s:streams):int
address mnstr_readIntwrap
comment "read integer data from the stream";

unsafe command flush( s:streams )
address mnstr_flush_streamwrap
comment "flush the stream";

unsafe command close( s:streams )
address mnstr_close_streamwrap
comment "close and destroy the stream s";

atom bstream:ptr;
unsafe command create(s:streams, bufsize:int):bstream
address bstream_create_wrapwrap
comment "create a buffered stream";

unsafe command destroy(s:bstream)
address bstream_destroy_wrapwrap
comment "destroy bstream";

unsafe command read(s:bstream,size:int):int
address bstream_read_wrapwrap
comment "read at least size bytes into the buffer of s";
