Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New and Improved io.Stream interface #2584

Merged
merged 8 commits into from
Jun 23, 2023
Merged

New and Improved io.Stream interface #2584

merged 8 commits into from
Jun 23, 2023

Conversation

gingerBill
Copy link
Member

@gingerBill gingerBill commented Jun 8, 2023

This is a big change which changes the io.Stream interface from being a hybrid inheritance model (pointer-to-vtable + data) to a flat model (procedure-value + data) which is more akin to a runtime.Allocator.

The number of stream "modes" has been greatly reduced to remove unnecessary and confusing options:

Stream_Mode :: enum {
	Close,
	Flush,
	Read,
	Read_At,
	Write,
	Write_At,
	Seek,
	Size,
	Destroy,
	Query, // query what modes are available
}

Stream_Proc :: #type proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, offset: i64, whence: Seek_From) -> (n: i64, err: Error)

Stream :: struct {
	procedure: Stream_Proc,
	data:      rawptr,
}

The io.Writer etc types are now just aliases of io.Stream rather than being distinct data types.


In core:os/os2, the File type now uses the io.Stream internally for its general operations meaning a stream can pretend to be a file if necessary (similar to open_memstream).

@gingerBill gingerBill marked this pull request as ready for review June 10, 2023 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant