MAT.jl icon indicating copy to clipboard operation
MAT.jl copied to clipboard

Read IOStream for use with S3

Open rob-luke opened this issue 10 years ago • 3 comments

Is it possible to pass an IOBuffer to MAT.jl?

This would be useful when storing data on services such as Amazon S3 with AWS.jl. I tried the following code, but it did not work.

using AWS
using AWS.S3
env = AWSEnv(); bkt = "???"

file = S3.get_object(env, bkt, "testfile.mat").obj
#IOBuffer(data=Uint8[...], readable=true, writable=true, seekable=true, append=false, size=1040, maxsize=Inf, ptr=1041, mark=-1)

vars = matread(file)
# ERROR: `matread` has no method matching matread(::IOBuffer)

rob-luke avatar Apr 17 '15 07:04 rob-luke

Would be great for this to get a more "proper" fix, but I think a simple (inefficient?) work-around for now could be something along the lines of:

function matread(io::IO)
    # Write to a temporary file
    tempfile = tempname()
    write(tempfile, io)

    # Read data from temporary file
    data = matread(tempfile)

    # Clean up temporary file and return data
    rm(tempfile)
    return data
end

Would need a bit of work to make sure errors, etc. are handled correctly (e.g., what should be done if io is empty?).

@JeffFessler, is this something you're still looking at?

dahong67 avatar Jun 14 '24 18:06 dahong67

I found a workaround of the form data = matread(Downloads.download(dataurl)) for my own use, e.g., https://juliaimagerecon.github.io/Examples/generated/mri/5-l-plus-s/#Read-data (You might be amused to see whose work is cited there.)

That does not address the OP question though, and it still (inefficiently?) uses an intermediate file.

JeffFessler avatar Jun 14 '24 18:06 JeffFessler

You might be amused to see whose work is cited there

Fun! Just showed her. :)

dahong67 avatar Jun 17 '24 01:06 dahong67