# JLD2 - load from IOBuffer

**URL:** <https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641>\
**Category:** General Usage\
**Tags:** package, jld2, serialization\
**Created:** [September 3, 2021, 12:28pm UTC](https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641 "2021-09-03T12:28:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwiese](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cwiese/32/4295_2.png) [@cwiese](https://discourse.julialang.org/u/cwiese)\
**Post date:** [September 3, 2021, 12:28pm UTC](https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641/1 "2021-09-03T12:28:15Z")

</div>

I am not finding a method to load a JLD2 file using `JLD2.load()` from IOBuffer. This seems basic for saving and loading to cloud like S3 or Azure Blob storage (which is my case). I would like to avoid reading from a REST call and saving locally - just to load again using a filename. Perhaps I am missing something?

---

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [January 3, 2024, 1:37pm UTC](https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641/2 "2024-01-03T13:37:43Z")

</div>

I am also searching for a way to load JLD2 using an `IO` stream and not a filename. Is there something ?

---

<div class="post-metadata">

**Author:** ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)\
**Post date:** [January 3, 2024, 2:18pm UTC](https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641/3 "2024-01-03T14:18:31Z")

</div>

Feature request issue [Load JLD2 from IOBuffer · Issue #346 · JuliaIO/JLD2.jl · GitHub](https://github.com/JuliaIO/JLD2.jl/issues/346)

---

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [November 20, 2025, 7:16pm UTC](https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641/4 "2025-11-20T19:16:35Z")

</div>

Bump this thread. I’m unsure what’s the status here, apparently it would be supported right now, but I’m trying to do it, and it fails.

```julia-auto
julia> load_object(open("/home/user/test.jld2"))
ERROR: type IOStream has no field readable

```

In my case, what I really want is to load from a xz compressed file, via a `XzDecompressorStream`. I don’t care so much if the file will be completely uncompressed to memory first, not touching the disk again is great for me. But right now I can’t even read from a simple IOStream, even though everywhere I read it seems possible. I can’t even find a work-around where I load the file to an array, I really need to load from a file via filename, it seems…

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 20, 2025, 8:41pm UTC](https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641/5 "2025-11-20T20:41:59Z")

</div>

I can reproduce your problem, using Julia 1.12.1 and JLD2 v0.6.2. Running the following script:

```julia-auto
using JLD2

hello = "world"
save_object("example.jld2", hello)
hello_loaded = load_object("example.jld2")
load_object(open("example.jld2")) # this line fails

```

results in the error:

```julia-auto
julia> include("test.jl")
ERROR: LoadError: FieldError: type IOStream has no field `readable`, available fields: `handle`, `ios`, `name`, `mark`, `lock`, `_dolock`
Stacktrace:
  [1] getproperty
    @ ./Base_compiler.jl:54 [inlined]
  [2] jldopen(io::IOStream, writable::Bool, create::Bool, truncate::Bool; plain::Bool, compress::Bool, typemap::Function)
    @ JLD2 ~/.julia/packages/JLD2/WDhXU/src/JLD2.jl:312
  [3] jldopen(io::IOStream, writable::Bool, create::Bool, truncate::Bool)
    @ JLD2 ~/.julia/packages/JLD2/WDhXU/src/JLD2.jl:304
  [4] jldopen(fname::IOStream, mode::String; iotype::Type, kwargs::@Kwargs{})
    @ JLD2 ~/.julia/packages/JLD2/WDhXU/src/JLD2.jl:299
  [5] jldopen(fname::IOStream, mode::String)
    @ JLD2 ~/.julia/packages/JLD2/WDhXU/src/JLD2.jl:290
  [6] jldopen(::Function, ::IOStream, ::Vararg{Any}; kws::@Kwargs{})
    @ JLD2 ~/.julia/packages/JLD2/WDhXU/src/loadsave.jl:2
  [7] jldopen(::Function, ::IOStream, ::String)
    @ JLD2 ~/.julia/packages/JLD2/WDhXU/src/loadsave.jl:1
  [8] load_object(filename::IOStream)
    @ JLD2 ~/.julia/packages/JLD2/WDhXU/src/loadsave.jl:248
  [9] top-level scope
    @ ~/tmp/test.jl:5
 [10] include(mapexpr::Function, mod::Module, _path::String)
    @ Base ./Base.jl:307
 [11] top-level scope
    @ REPL[1]:1
in expression starting at /home/ufechner/tmp/test.jl:5

```

I executed this test on Ubuntu 24.04.

Did you try the function `load` instead of `load_object` ?

UPDATE:  
OK, load does not help.

Did you try jldopen ?

---

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [November 20, 2025, 9:04pm UTC](https://discourse.julialang.org/t/jld2-load-from-iobuffer/67641/6 "2025-11-20T21:04:33Z")

</div>

It’s suboptimal that this errors as it does. That in itself is probably worth an issue.

Check out [JLD2.jl/test/wrapped\_io.jl at master · JuliaIO/JLD2.jl · GitHub](https://github.com/JuliaIO/JLD2.jl/blob/master/test/wrapped_io.jl)  
for tests of what is implemented, and check out  
[JLD2.jl/src/io/io\_wrappers.jl at master · JuliaIO/JLD2.jl · GitHub](https://github.com/JuliaIO/JLD2.jl/blob/master/src/io/io_wrappers.jl)  
for a discussion of requirements for IO types to be supported in JLD2.

Your current best bet would be to decompress your file into an `IOBuffer` (i.e. decompressing to `Vector{UInt8}` and wrapping that in an IOBuffer like so:

```julia-auto
julia> using JLD2

julia> jldsave("test.jld2"; a=collect(1:10))

julia> bytes = read("test.jld2")
884-element Vector{UInt8}:
 0x48
 0x44
....
julia> bytes = read("test.jld2");

julia> io = IOBuffer(bytes)
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=884, maxsize=Inf, ptr=1, mark=-1)

julia> jldopen(io) do f
       f["a"]
       end
10-element Vector{Int64}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

```

Consider this as highly experimental features. PRs to improve API, usability, docs, or even performance are very welcome.  
I had seen very little interest in these features the last few years so little effort went into developing these beyond a simple proof of concept implementation.

Note that a _streaming_ implementation will never be useful. JLD2 is a hierarchical format that needs random access to the file to decode it. There is no way to efficiently make use of a streaming API and therefore I would prefer not to add one.
