@@ -8,7 +8,6 @@ add_format(format"GZIP", [0x1f, 0x8b], ".gz", [:Libz])
88
99# test for RD?2 magic sequence at the beginning of R data input stream
1010function detect_rdata (io)
11- seekstart (io)
1211 read (io, UInt8) == UInt8 (' R' ) &&
1312 read (io, UInt8) == UInt8 (' D' ) &&
1413 read (io, UInt8) in (UInt8 (' A' ), UInt8 (' B' ), UInt8 (' X' )) &&
1918add_format (format " RData" , detect_rdata, [" .rda" , " .RData" , " .rdata" ], [:RData , LOAD])
2019
2120function detect_rdata_single (io)
22- seekstart (io)
2321 res = read (io, UInt8) in (UInt8 (' A' ), UInt8 (' B' ), UInt8 (' X' )) &&
2422 (c = read (io, UInt8); c == UInt8 (' \n ' ) || (c == UInt8 (' \r ' ) && read (io, UInt8) == UInt8 (' \n ' )))
25- seekstart (io)
2623 return res
2724end
2825
@@ -145,10 +142,9 @@ add_format(format"GSLIB", (), [".gslib",".sgems"], [:GslibIO])
145142
146143# ## Audio formats
147144function detectwav (io)
148- seekstart (io)
149145 magic = read! (io, Vector {UInt8} (4 ))
150146 magic == b " RIFF" || return false
151- seek (io, 8 )
147+ skip (io, 4 )
152148 submagic = read! (io, Vector {UInt8} (4 ))
153149
154150 submagic == b " WAVE"
@@ -200,10 +196,9 @@ skipmagic(io, ::typeof(detect_noometiff)) = seek(io, 4)
200196
201197# AVI is a subtype of RIFF, as is WAV
202198function detectavi (io)
203- seekstart (io)
204199 magic = read! (io, Vector {UInt8} (4 ))
205200 magic == b " RIFF" || return false
206- seek (io, 8 )
201+ skip (io, 4 )
207202 submagic = read! (io, Vector {UInt8} (4 ))
208203
209204 submagic == b " AVI "
@@ -212,6 +207,8 @@ add_format(format"AVI", detectavi, ".avi", [:ImageMagick])
212207
213208# HDF5: the complication is that the magic bytes may start at
214209# 0, 512, 1024, 2048, or any multiple of 2 thereafter
210+ # this detection function assumes that the stream start and end match the
211+ # file start and end, which is true if it's just a file on disk
215212h5magic = (0x89 ,0x48 ,0x44 ,0x46 ,0x0d ,0x0a ,0x1a ,0x0a )
216213function detecthdf5 (io)
217214 position (io) == 0 || return false
@@ -234,6 +231,8 @@ function detecthdf5(io)
234231end
235232add_format (format " HDF5" , detecthdf5, [" .h5" , " .hdf5" ], [:HDF5 ])
236233
234+ # the STL detection functions assumes that the stream start and end match the
235+ # file start and end, which is true if it's just a file on disk
237236function detect_stlascii (io)
238237 try
239238 position (io) != 0 && (seekstart (io); return false )
0 commit comments