Skip to content

Commit 5fb37db

Browse files
committed
some README fixes [ci skip]
1 parent ff9fe57 commit 5fb37db

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ try
5656
# process the chunk
5757
end
5858
finally
59-
close(stream)
59+
close(audio)
6060
end
6161
```
6262

6363
or use `do` syntax to auto-close the stream:
6464

6565
```jl
6666
using FileIO
67-
do loadstreaming("bigfile.wav") audio
67+
loadstreaming("bigfile.wav") do audio
6868
while !eof(audio)
6969
chunk = read(audio, 4096) # read 4096 frames
7070
# process the chunk
@@ -185,7 +185,7 @@ closing any streams you opened in order to read or write the file. If you are
185185
given a `Stream`, your `close` method should only do the clean up for your
186186
reader or writer type, not close the stream.
187187

188-
```julia
188+
```jl
189189
struct WAVReader
190190
io::IO
191191
ownstream::Bool
@@ -197,28 +197,26 @@ end
197197

198198
function close(reader::WAVReader)
199199
# do whatever cleanup the reader needs
200-
if reader.ownstream
201-
close(reader.io)
202-
end
200+
reader.ownstream && close(reader.io)
203201
end
204-
loadstreaming(f::File{format"WAV"}) = WAVReader(open(f), ownstream=true)
205-
loadstreaming(s::Stream{format"WAV"}) = WAVReader(s, ownstream=false)
202+
loadstreaming(f::File{format"WAV"}) = WAVReader(open(f), true)
203+
loadstreaming(s::Stream{format"WAV"}) = WAVReader(s, false)
206204
# FileIO has fallback functions that make these work using `do` syntax as well.
207205
```
208206

209207
If you choose to implement `loadstreaming` and `savestreaming` in your package,
210208
you can easily add `save` and `load` methods in the form of:
211209

212-
```julia
210+
```jl
213211
function save(q::Formatted{format"WAV"}, data, args...; kwargs...)
214-
savestreaming(args...; kwargs...) do stream
212+
savestreaming(q, args...; kwargs...) do stream
215213
write(stream, data)
216214
end
217215
end
218216

219217
function load(q::Formatted{format"WAV"}, args...; kwargs...)
220-
savestreaming(args...; kwargs...) do stream
221-
readall(stream)
218+
savestreaming(q, args...; kwargs...) do stream
219+
read(stream)
222220
end
223221
end
224222
```

0 commit comments

Comments
 (0)