Skip to content

Commit 239af17

Browse files
committed
fixes some documentation issues spotted by @timholy
1 parent 0f5930c commit 239af17

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ end
168168
Note that these are `load` and `save`, **not** `FileIO.load` and `FileIO.save`.
169169
Because a given format might have multiple packages that are capable of reading it,
170170
FileIO will dispatch to these using module-scoping, e.g., `SomePkg.load(args...)`.
171-
Consequently, **packages should define "private" `load` and `save` methods, and
172-
not extend (import) FileIO's**.
171+
Consequently, **packages should define "private" `load` and `save` methods (also
172+
`loadstreaming` and `savestreaming` if you implement them), and not extend
173+
(import) FileIO's**.
173174

174175
`load(::File)` and `save(::File)` should close any streams
175176
they open. (If you use the `do` syntax, this happens for you
@@ -191,17 +192,19 @@ struct WAVReader
191192
ownstream::Bool
192193
end
193194

194-
function read(reader::WAVReader, frames::Int)
195+
function Base.read(reader::WAVReader, frames::Int)
195196
# read and decode audio samples from reader.io
196197
end
197198

198-
function close(reader::WAVReader)
199+
function Base.close(reader::WAVReader)
199200
# do whatever cleanup the reader needs
200201
reader.ownstream && close(reader.io)
201202
end
203+
204+
# FileIO has fallback functions that make these work using `do` syntax as well,
205+
# and will automatically call `close` on the returned object.
202206
loadstreaming(f::File{format"WAV"}) = WAVReader(open(f), true)
203207
loadstreaming(s::Stream{format"WAV"}) = WAVReader(s, false)
204-
# FileIO has fallback functions that make these work using `do` syntax as well.
205208
```
206209

207210
If you choose to implement `loadstreaming` and `savestreaming` in your package,
@@ -215,7 +218,7 @@ function save(q::Formatted{format"WAV"}, data, args...; kwargs...)
215218
end
216219

217220
function load(q::Formatted{format"WAV"}, args...; kwargs...)
218-
savestreaming(q, args...; kwargs...) do stream
221+
loadstreaming(q, args...; kwargs...) do stream
219222
read(stream)
220223
end
221224
end

src/loadsave.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ add_saver
4444
- `load(filename)` loads the contents of a formatted file, trying to infer
4545
the format from `filename` and/or magic bytes in the file.
4646
- `load(strm)` loads from an `IOStream` or similar object. In this case,
47-
the magic bytes are essential.
48-
- `load(File(format"PNG",filename))` specifies the format directly, and bypasses inference.
47+
there is no filename extension, so we rely on the magic bytes for format
48+
identification.
49+
- `load(File(format"PNG", filename))` specifies the format directly, and bypasses inference.
50+
- `load(Stream(format"PNG", io))` specifies the format directly, and bypasses inference.
4951
- `load(f; options...)` passes keyword arguments on to the loader.
5052
"""
5153
load
@@ -60,17 +62,22 @@ video or audio.
6062
the format from `filename` and/or magic bytes in the file. It returns a streaming
6163
type that can be read from in chunks, rather than loading the whole contents all
6264
at once
63-
- `loadstreaming(strm)` loads the stream from an `IOStream` or similar object. In this case,
64-
the magic bytes are essential.
65-
- `load(File(format"PNG",filename))` specifies the format directly, and bypasses inference.
66-
- `load(f; options...)` passes keyword arguments on to the loader.
65+
- `loadstreaming(strm)` loads the stream from an `IOStream` or similar object.
66+
In this case, there is no filename extension, so we rely on the magic bytes
67+
for format identification.
68+
- `loadstreaming(File(format"WAV",filename))` specifies the format directly, and
69+
bypasses inference.
70+
- `loadstreaming(Stream(format"WAV", io))` specifies the format directly, and
71+
bypasses inference.
72+
- `loadstreaming(f; options...)` passes keyword arguments on to the loader.
6773
"""
6874
loadstreaming
6975

7076
"""
7177
- `save(filename, data...)` saves the contents of a formatted file,
7278
trying to infer the format from `filename`.
7379
- `save(Stream(format"PNG",io), data...)` specifies the format directly, and bypasses inference.
80+
- `save(File(format"PNG",filename), data...)` specifies the format directly, and bypasses inference.
7481
- `save(f, data...; options...)` passes keyword arguments on to the saver.
7582
"""
7683
save
@@ -82,7 +89,10 @@ accept formatted objects, like an image or chunk of video or audio.
8289
8390
- `savestreaming(filename, data...)` saves the contents of a formatted file,
8491
trying to infer the format from `filename`.
85-
- `savestreaming(Stream(format"PNG",io), data...)` specifies the format directly, and bypasses inference.
92+
- `savestreaming(File(format"WAV",filename))` specifies the format directly, and
93+
bypasses inference.
94+
- `savestreaming(Stream(format"WAV", io))` specifies the format directly, and
95+
bypasses inference.
8696
- `savestreaming(f, data...; options...)` passes keyword arguments on to the saver.
8797
"""
8898
savestreaming

0 commit comments

Comments
 (0)