JuliaIO / JuliaIO/FileIO.jl

should `load(::Stream, ...)` methods skip magic bytes?

Open
#163 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
228
Forks
81
Avg merge
1d 29m
Merged PRs (30d)
1

Description

In the README, the example for loading from a stream is:

function load(f::File{format"PNG"})
  open(f) do s
  skipmagic(s) # skip over the magic bytes
  # You can just call the method below...
  ret = load(s)
  # ...or implement everything here instead
  end
end

# You can support streams and add keywords:
function load(s::Stream{format"PNG"}; keywords...)
  # s is already positioned after the magic bytes
  # Do the stuff to read a PNG file
  chunklength = read(s, UInt32)
  ...
end

This works if the user calls load("somefile.png"), which will end up calling the load(::File, ...) method, which handles skipping the magic bytes before calling load(::Stream). What I'm not super clear on is how this is intended to be used directly. e.g. I couldn't just do:

open("somefile.png") do io
    load(io)
end

In ImageMagick.jl it looks like load is called on the IO stream directly without skipping the magic(k) bytes.

So if it seems like the way ImageMagick does it (leaving the stream at the very beginning of the file when calling load(::Stream)) I can put in a documentation PR that clarifies that.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the README stream-loading example and inspect the linked ImageMagick.jl test at test/constructed_images.jl lines 195-201. Confirm the intended position of the stream when load(::Stream) is called, then update the README to state the contract and usage clearly if maintainers confirm it.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.