I have curl command, whose input I want to load using BSON. For performance reason, I want to read the curl output directly to memory, without saving it to file. Also, I want to close the curl as soon as possible, so I want to read data from curl and then to pass them to BSON, we had some problems when curl was open because it was faster than consecutive parsing.
I know this works, but it keeps curl open for too long, which causes problems when we do this in parallel many times at once and the server where we download from is a bit busy.
using BSON
cmd = `curl <some data>`
BSON.load(open(cmd))
To close cmd
ASAP, I have this:
# created IOBuffer to wrap bytes
import BSON.load
function BSON.load(bytes::Vector{UInt8})
io = IOBuffer()
write(io, bytes)
seekstart(io)
BSON.load(io)
end
cmd = `curl <some data>`
BSON.load(read(cmd))
which works, but I consider it very ugly. Also I'm not sure if this doesn't have some performance penalty.
Is there a more elegant way to do this? Can I read(cmd)
into some IO structure, which could be then passed to BSON.load
?
I realized the exactly same problem holds for Serialization.deserialize
. My solution for deserialization is same, but I welcome any improvoements.