Skip to content

Commit

Permalink
Merge pull request #164 from JuliaIO/teh/README_scope
Browse files Browse the repository at this point in the history
Clarify that load and save should not be extended
  • Loading branch information
timholy authored Nov 27, 2017
2 parents 4bf7c2e + cfc96d5 commit 2886a42
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ In your package, write code like the following:
```jl
using FileIO

# See important note about scope below
function load(f::File{format"PNG"})
open(f) do s
skipmagic(s) # skip over the magic bytes
Expand All @@ -126,7 +127,13 @@ function save(f::File{format"PNG"}, data)
end
```

Note that `load(::File)` and `save(::File)` should close any streams
Note that these are `load` and `save`, **not** `FileIO.load` and `FileIO.save`.
Because a given format might have multiple packages that are capable of reading it,
FileIO will dispatch to these using module-scoping, e.g., `SomePkg.load(args...)`.
Consequently, **packages should define "private" `load` and `save` methods, and
not extend (import) FileIO's**.

`load(::File)` and `save(::File)` should close any streams
they open. (If you use the `do` syntax, this happens for you
automatically even if the code inside the `do` scope throws an error.)
Conversely, `load(::Stream)` and `save(::Stream)` should not close the
Expand Down

0 comments on commit 2886a42

Please sign in to comment.