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

write(to::IO, from::IO) #14628

Closed
samoconnor opened this issue Jan 10, 2016 · 5 comments
Closed

write(to::IO, from::IO) #14628

samoconnor opened this issue Jan 10, 2016 · 5 comments
Labels
domain:io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@samoconnor
Copy link
Contributor

I have some code like this:

    stream = s3(aws, "GET", key)
    open(filename, "w") do file
        while !eof(stream)
            write(file, readavailable(stream))
        end
    end

With write(to::IO, from::IO) it could be reduced to:

stream = s3(aws, "GET", key)
open(filename, "w") do f write(f, stream) end

or even just...

write(filename, s3(aws, "GET", key))

This is not just about terse code.
The write(readavailable()) loop is potentially quite memory inefficient. If the task has been suspended for a while, the stream could have many MB available and depending on how stream buffering is implemented large buffers could be duplicated.

It seems like it would be better to have a write(to::IO, from::IO) API so that shortcut implementations can be created to directly connect two streams at a low level where that is more efficient.
e.g. this could map to sendfile() in some cases.

The default can just be:

write(to::IO, from::IO) = while !eof(from) write(to, readavailable(from)) end
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 11, 2016

I agree

@StefanKarpinski
Copy link
Sponsor Member

+1

@tkelman tkelman added the domain:io Involving the I/O subsystem: libuv, read, write, etc. label Jan 11, 2016
@samoconnor
Copy link
Contributor Author

Included in #14660
closing

@samoconnor
Copy link
Contributor Author

@swt30
Copy link
Contributor

swt30 commented Jan 21, 2016

Ah, thank you - I was thinking about this just last night while writing from one stream to another. It seemed odd to me that this method didn't already exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

5 participants