@@ -126,43 +126,54 @@ savestreaming(s::Stream{format"DUMMY"}) = DummyWriter(s, false)
126
126
savestreaming (file:: File{format"DUMMY"} ) = DummyWriter (open (file, " w" ), true )
127
127
128
128
# we could implement `load` and `save` in terms of their streaming versions
129
- function FileIO . load (file:: File{format"DUMMY"} )
129
+ function load (file:: File{format"DUMMY"} ; extra = UInt8[] )
130
130
open (file) do s
131
- load (s)
131
+ load (s; extra = extra )
132
132
end
133
133
end
134
134
135
- function FileIO . metadata (file:: File{format"DUMMY"} )
135
+ function metadata (file:: File{format"DUMMY"} )
136
136
s = open (file)
137
137
skipmagic (s)
138
138
n = read (s, Int64)
139
139
close (s)
140
140
return n
141
141
end
142
142
143
- function FileIO . load (s:: Stream{format"DUMMY"} )
143
+ function load (s:: Stream{format"DUMMY"} ; extra = UInt8[] )
144
144
skipmagic (s)
145
145
n = read (s, Int64)
146
146
out = Vector {UInt8} (undef, n)
147
147
read! (s, out)
148
+ # verify that the extradata is as expected. This is just to test that
149
+ # the keyword arguments are handled properly in loading and saving
150
+ extradata = read (s, length (extra))
151
+ if extradata != extra
152
+ throw (ErrorException (" Got extra data $extradata instead of $extra " ))
153
+ end
148
154
close (s)
149
155
out
150
156
end
151
157
152
- function save (file:: File{format"DUMMY"} , data)
158
+ function save (file:: File{format"DUMMY"} , data; extra = UInt8[] )
153
159
open (file, " w" ) do s
154
- write (s, magic (format " DUMMY" )) # Write the magic bytes
155
- write (s, convert (Int64, length (data)))
156
- udata = convert (Vector{UInt8}, data)
157
- write (s, udata)
160
+ save (s, data; extra= extra)
158
161
end
159
162
end
160
163
164
+ function save (s:: Stream{format"DUMMY"} , data; extra= UInt8[])
165
+ write (s, magic (format " DUMMY" )) # Write the magic bytes
166
+ write (s, convert (Int64, length (data)))
167
+ udata = convert (Vector{UInt8}, data)
168
+ write (s, udata)
169
+ write (s, extra)
161
170
end
162
171
163
172
add_loader (format " DUMMY" , :Dummy )
164
173
add_saver (format " DUMMY" , :Dummy )
165
174
175
+ end # module Dummy
176
+
166
177
@testset " Save" begin
167
178
a = [0x01 ,0x02 ,0x03 ]
168
179
fn = string (tempname (), " .dmy" )
@@ -268,6 +279,13 @@ add_saver(format"DUMMY", :Dummy)
268
279
@test load (fn) == a
269
280
rm (fn)
270
281
282
+ # test keyword arguments
283
+
284
+ a = [0x01 ,0x02 ,0x03 ]
285
+ fn = string (tempname (), " .dmy" )
286
+ save (fn, a; extra= [0x42 , 0x43 ])
287
+ # the loader verifies that the extra data was written properly
288
+ load (fn; extra= [0x42 , 0x43 ])
271
289
272
290
@test_throws Exception save (" missing.fmt" ,5 )
273
291
end
0 commit comments