Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ for (applicable_, add_, dict_) in (
end


"`add_loader(fmt, :Package)` triggers `using Package` before loading format `fmt`"
"""
add_loader(fmt, :Package)
add_loader(fmt, [:Package, specifiers...])

Declare that format `fmt` can be loaded with package `:Package`.
Specifiers include `OSX`, `Unix`, `Windows` and `Linux` to restrict usage to particular operating systems.
"""
add_loader
"`add_saver(fmt, :Package)` triggers `using Package` before saving format `fmt`"

"""
add_saver(fmt, :Package)
add_saver(fmt, [:Package, specifiers...])

Declare that format `fmt` can be saved with package `:Package`.
Specifiers include `OSX`, `Unix`, `Windows` and `Linux` to restrict usage to particular operating systems.
"""
add_saver

"""
Expand Down
12 changes: 11 additions & 1 deletion src/registry_setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,24 @@ function add_format(fmt, magic, extension, load_save_libraries...)
end

"""
`add_format(fmt, magic, extention)` registers a new `DataFormat`.
`add_format(fmt, magic, extension)` registers a new `DataFormat`.
For example:

add_format(format"TIFF", (UInt8[0x4d,0x4d,0x00,0x2b], UInt8[0x49,0x49,0x2a,0x00]), [".tiff", ".tif"])
add_format(format"PNG", [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a], ".png")
add_format(format"NRRD", "NRRD", [".nrrd",".nhdr"])

Note that extensions, magic numbers, and format-identifiers are case-sensitive.

You can also specify particular packages that support the format with `add_format(fmt, magic, extension, pkgspecifiers...)`,
where example `pkgspecifiers` are:

add_format(fmt, magic, extension, [:PkgA]) # only PkgA supports the format (load & save)
add_format(fmt, magic, extension, [:PkgA], [:PkgB]) # try PkgA first, but if it fails try PkgB
add_format(fmt, magic, extension, [:PkgA, LOAD], [:PkgB]) # try PkgA first for `load`, otherwise use PkgB
add_format(fmt, magic, extension, [:PkgA, OSX], [:PkgB]) # use PkgA on OSX, and PkgB otherwise

You can combine `LOAD`, `SAVE`, `OSX`, `Unix`, `Windows` and `Linux` arbitrarily to narrow `pkgspecifiers`.
"""
function add_format(fmt::Type{DataFormat{sym}}, magic::Union{Tuple,AbstractVector,String}, extension) where sym
haskey(sym2info, sym) && error("format ", fmt, " is already registered")
Expand Down