@@ -11,10 +11,11 @@ immutable SAVE end
11
11
split_predicates (list) = filter (x-> x <: OS , list), filter (x-> ! (x <: OS ), list)
12
12
applies_to_os (os:: Vector ) = isempty (os) || any (applies_to_os, os)
13
13
applies_to_os {O <: OS} (os:: Type{O} ) = false
14
- @unix_only applies_to_os {U <: Unix} (os:: Type{U} ) = true
15
- @windows_only applies_to_os (os:: Type{Windows} ) = true
16
- @linux_only applies_to_os (os:: Type{OSX} ) = false
17
- @osx_only applies_to_os (os:: Type{Linux} ) = false
14
+
15
+ applies_to_os {U <: Unix} (os:: Type{U} ) = is_unix ()
16
+ applies_to_os (os:: Type{Windows} ) = is_windows ()
17
+ applies_to_os (os:: Type{OSX} ) = is_apple ()
18
+ applies_to_os (os:: Type{Linux} ) = is_linux ()
18
19
19
20
function add_loadsave (format, predicates)
20
21
library = shift! (predicates)
@@ -29,13 +30,13 @@ function add_loadsave(format, predicates)
29
30
end
30
31
end
31
32
32
- @doc """
33
+ """
33
34
`DataFormat{sym}()` indicates a known binary or text format of kind `sym`,
34
35
where `sym` is always a symbol. For example, a .csv file might have
35
36
`DataFormat{:CSV}()`.
36
37
37
38
An easy way to write `DataFormat{:CSV}` is `format"CSV"`.
38
- """ ->
39
+ """
39
40
immutable DataFormat{sym} end
40
41
41
42
macro format_str (s)
44
45
45
46
const unknown_df = DataFormat{:UNKNOWN }
46
47
47
- @doc """
48
- `unknown(f)` returns true if the format of `f` is unknown.""" ->
48
+ """
49
+ `unknown(f)` returns true if the format of `f` is unknown."""
49
50
unknown (:: Type{format"UNKNOWN"} ) = true
50
51
unknown {sym} (:: Type{DataFormat{sym}} ) = false
51
52
@@ -63,7 +64,7 @@ function add_format(fmt, magic, extension, load_save_libraries...)
63
64
fmt
64
65
end
65
66
66
- @doc """
67
+ """
67
68
`add_format(fmt, magic, extention)` registers a new `DataFormat`.
68
69
For example:
69
70
@@ -72,7 +73,7 @@ For example:
72
73
add_format(format"NRRD", "NRRD", [".nrrd",".nhdr"])
73
74
74
75
Note that extensions, magic numbers, and format-identifiers are case-sensitive.
75
- """ ->
76
+ """
76
77
function add_format {sym} (fmt:: Type{DataFormat{sym}} , magic: :@compat (Union{Tuple,AbstractVector,String}), extension)
77
78
haskey (sym2info, sym) && error (" format " , fmt, " is already registered" )
78
79
m = canonicalize_magic (magic)
@@ -112,9 +113,9 @@ function add_format{sym}(fmt::Type{DataFormat{sym}}, magic, extension)
112
113
fmt
113
114
end
114
115
115
- @doc """
116
+ """
116
117
`del_format(fmt::DataFormat)` deletes `fmt` from the format registry.
117
- """ ->
118
+ """
118
119
function del_format {sym} (fmt:: Type{DataFormat{sym}} )
119
120
magic, extension = sym2info[sym]
120
121
del_magic (magic, sym)
@@ -147,9 +148,9 @@ function del_magic{N}(magic::NTuple{N, UInt8}, sym)
147
148
nothing
148
149
end
149
150
150
- @doc """
151
+ """
151
152
`info(fmt)` returns the magic bytes/extension information for
152
- `DataFormat` `fmt`.""" ->
153
+ `DataFormat` `fmt`."""
153
154
Base. info {sym} (:: Type{DataFormat{sym}} ) = sym2info[sym]
154
155
155
156
@@ -208,53 +209,53 @@ end
208
209
209
210
abstract Formatted{F<: DataFormat } # A specific file or stream
210
211
211
- @doc """
212
+ """
212
213
`File(fmt, filename)` indicates that `filename` is a file of known
213
214
DataFormat `fmt`. For example, `File{fmtpng}(filename)` would indicate a PNG
214
- file.""" ->
215
+ file."""
215
216
immutable File{F<: DataFormat } <: Formatted{F}
216
217
filename:: Compat.UTF8String
217
218
end
218
219
File {sym} (fmt:: Type{DataFormat{sym}} , filename) = File {fmt} (filename)
219
220
220
- @doc """
221
+ """
221
222
`filename(file)` returns the filename associated with `File` `file`.
222
- """ ->
223
+ """
223
224
filename (f:: File ) = f. filename
224
225
225
- @doc """
226
+ """
226
227
`file_extension(file)` returns the file extension associated with `File` `file`.
227
- """ ->
228
+ """
228
229
file_extension (f:: File ) = splitext (filename (f))[2 ]
229
230
230
231
231
232
232
- @doc """
233
+ """
233
234
`Stream(fmt, io, [filename])` indicates that the stream `io` is
234
235
written in known `Format`. For example, `Stream{PNG}(io)` would
235
236
indicate PNG format. If known, the optional `filename` argument can
236
- be used to improve error messages, etc.""" ->
237
+ be used to improve error messages, etc."""
237
238
immutable Stream{F<: DataFormat ,IOtype<: IO } <: Formatted{F}
238
239
io:: IOtype
239
240
filename:: Nullable{Compat.UTF8String}
240
241
end
241
242
242
243
Stream {F<:DataFormat} (:: Type{F} , io:: IO ) = Stream {F,typeof(io)} (io, Nullable {Compat.UTF8String} ())
243
- Stream {F<:DataFormat} (:: Type{F} , io:: IO , filename:: AbstractString ) = Stream {F,typeof(io)} (io,utf8 (filename))
244
+ Stream {F<:DataFormat} (:: Type{F} , io:: IO , filename:: AbstractString ) = Stream {F,typeof(io)} (io,Compat . UTF8String (filename))
244
245
Stream {F<:DataFormat} (:: Type{F} , io:: IO , filename) = Stream {F,typeof(io)} (io,filename)
245
246
Stream {F} (file:: File{F} , io:: IO ) = Stream {F,typeof(io)} (io,filename (file))
246
247
247
- @doc " `stream(s)` returns the stream associated with `Stream` `s`" ->
248
+ " `stream(s)` returns the stream associated with `Stream` `s`"
248
249
stream (s:: Stream ) = s. io
249
250
250
- @doc """
251
+ """
251
252
`filename(stream)` returns a nullable-string of the filename
252
- associated with `Stream` `stream`.""" ->
253
+ associated with `Stream` `stream`."""
253
254
filename (s:: Stream ) = s. filename
254
255
255
- @doc """
256
+ """
256
257
`file_extension(file)` returns a nullable-string for the file extension associated with `Stream` `stream`.
257
- """ ->
258
+ """
258
259
function file_extension (f:: Stream )
259
260
isnull (filename (f)) && return filename (f)
260
261
splitext (get (filename (f)))[2 ]
@@ -300,13 +301,13 @@ Base.readbytes(s::Stream, nb) = read(stream(s), nb)
300
301
Base. isreadonly (s:: Stream ) = isreadonly (stream (s))
301
302
Base. isopen (s:: Stream ) = isopen (stream (s))
302
303
303
- @doc " `magic(fmt)` returns the magic bytes of format `fmt`" ->
304
+ " `magic(fmt)` returns the magic bytes of format `fmt`"
304
305
magic {F<:DataFormat} (fmt:: Type{F} ) = UInt8[info (fmt)[1 ]. .. ]
305
306
306
- @doc """
307
+ """
307
308
`skipmagic(s)` sets the position of `Stream` `s` to be just after the magic bytes.
308
309
For a plain IO object, you can use `skipmagic(io, fmt)`.
309
- """ ->
310
+ """
310
311
skipmagic {F} (s:: Stream{F} ) = (skipmagic (stream (s), F); s)
311
312
function skipmagic {sym} (io, fmt:: Type{DataFormat{sym}} )
312
313
magic, _ = sym2info[sym]
344
345
unknown {F} (:: File{F} ) = unknown (F)
345
346
unknown {F} (:: Stream{F} ) = unknown (F)
346
347
347
- @doc """
348
+ """
348
349
`query(filename)` returns a `File` object with information about the
349
- format inferred from the file's extension and/or magic bytes.""" ->
350
+ format inferred from the file's extension and/or magic bytes."""
350
351
function query (filename:: AbstractString )
351
352
_, ext = splitext (filename)
352
353
if haskey (ext2sym, ext)
@@ -380,10 +381,10 @@ hasfunction(v::Vector) = any(hasfunction, v)
380
381
hasfunction (s:: Any ) = true # has function
381
382
hasfunction (s:: Tuple ) = false # has magic
382
383
383
- @doc """
384
+ """
384
385
`query(io, [filename])` returns a `Stream` object with information about the
385
- format inferred from the magic bytes.""" ->
386
- query (io:: IO , filename) = query (io, Nullable (utf8 (filename)))
386
+ format inferred from the magic bytes."""
387
+ query (io:: IO , filename) = query (io, Nullable (Compat . UTF8String (filename)))
387
388
388
389
function query (io:: IO , filename:: Nullable{Compat.UTF8String} = Nullable {Compat.UTF8String} ())
389
390
magic = Array (UInt8, 0 )
0 commit comments