You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered what appears to be a small bug in close(::GenericIOBuffer). Here is the code from v1.5.3
@noinline function close(io::Base.GenericIOBuffer{T}) where T
io.readable = false
io.writable = false
io.seekable = false
io.size = 0
io.maxsize = 0
io.ptr = 1
io.mark = -1
if io.writable
resize!(io.data, 0)
end
nothing
end
The first issue is just that the "if io.writable" condition can never be true because writable is set to false earlier in the function. I don't understand why we should even want to resize the data to zero in any case though since you can optionally provide this data yourself in the IOBuffer constructor. I think most users would find their data array being resized to zero to be an unhelpful surprise.
The second issue which is more important is that close() is very aggressive about resetting the size and ptr fields, making the data effectively inaccessible. This causes difficulties when using GenericIOBuffer as a stream that's been wrapped by another stream ie:
The issue is that compressor won't necessarily have written all of its output to the IOBuffer until it has been closed, and closing it calls close on the IOBuffer, rendering the data inaccessible (besides manually inspecting the data field). There is no way to tell how many bytes were actually written to data, unless data was extended in size because it was too small.
I'm not sure if there would be any bad effects to making close(::GenericIOBuffer) less aggressive, perhaps only setting writable to false and otherwise doing nothing. It seems like this is a case where the behavior you expect from a buffer and the behavior you expect from a stream diverge.
The text was updated successfully, but these errors were encountered:
I don't remember what the exact issue was; it may have been as simple as that Base.BufferStream doesn't inherit from the right abstract interface for usage with HTTP. In any case, SimpleBufferStream does work pretty well for what it is (it's not fully-featured, e.g. there's no mark()/unmark() interface).
I encountered what appears to be a small bug in close(::GenericIOBuffer). Here is the code from v1.5.3
The first issue is just that the "if io.writable" condition can never be true because writable is set to false earlier in the function. I don't understand why we should even want to resize the data to zero in any case though since you can optionally provide this data yourself in the IOBuffer constructor. I think most users would find their data array being resized to zero to be an unhelpful surprise.
The second issue which is more important is that close() is very aggressive about resetting the size and ptr fields, making the data effectively inaccessible. This causes difficulties when using GenericIOBuffer as a stream that's been wrapped by another stream ie:
The issue is that compressor won't necessarily have written all of its output to the IOBuffer until it has been closed, and closing it calls close on the IOBuffer, rendering the data inaccessible (besides manually inspecting the data field). There is no way to tell how many bytes were actually written to data, unless data was extended in size because it was too small.
I'm not sure if there would be any bad effects to making close(::GenericIOBuffer) less aggressive, perhaps only setting writable to false and otherwise doing nothing. It seems like this is a case where the behavior you expect from a buffer and the behavior you expect from a stream diverge.
The text was updated successfully, but these errors were encountered: