Skip to content

Commit 1eb64bc

Browse files
committed
Merge pull request #48 from ssfrr/avi-detect
Changes AVI detection to a function that ignores WAV files
2 parents edd8d8d + 9d24c84 commit 1eb64bc

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/registry.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ add_format(format"NRRD", "NRRD", [".nrrd", ".nhdr"], [:NRRD])
1414
add_format(format"AndorSIF", "Andor Technology Multi-Channel File", ".sif", [:AndorSIF, LOAD])
1515

1616

17-
add_format(format"AVI", UInt8[0x52,0x49,0x46,0x46], ".avi", [:ImageMagick])
1817
add_format(format"CRW", UInt8[0x49,0x49,0x1a,0x00,0x00,0x00,0x48,0x45], ".crw", [:ImageMagick])
1918
add_format(format"CUR", UInt8[0x00,0x00,0x02,0x00], ".cur", [:ImageMagick])
2019
add_format(format"DCX", UInt8[0xb1,0x68,0xde,0x3a], ".dcx", [:ImageMagick])
@@ -100,6 +99,19 @@ add_format(format"OFF", "OFF", ".off", [:MeshIO])
10099

101100

102101
### Complex cases
102+
103+
# AVI is a subtype of RIFF, as is WAV
104+
function detectavi(io)
105+
seekstart(io)
106+
magic = ascii(read(io, UInt8, 4))
107+
magic == "RIFF" || return false
108+
seek(io, 8)
109+
submagic = ascii(read(io, UInt8, 4))
110+
111+
submagic == "AVI "
112+
end
113+
add_format(format"AVI", detectavi, ".avi", [:ImageMagick])
114+
103115
# HDF5: the complication is that the magic bytes may start at
104116
# 0, 512, 1024, 2048, or any multiple of 2 thereafter
105117
h5magic = (0x89,0x48,0x44,0x46,0x0d,0x0a,0x1a,0x0a)

test/files/bees.avi

768 KB
Binary file not shown.

test/files/sin.wav

444 Bytes
Binary file not shown.

test/query.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,16 @@ context("Multiple Magic bytes") do
292292
@fact position(io) --> 4
293293
end
294294
end
295+
context("AVI Detection") do
296+
open(joinpath(file_dir, "bees.avi")) do s
297+
@fact FileIO.detectavi(s) --> true
298+
end
299+
open(joinpath(file_dir, "sin.wav")) do s
300+
@fact FileIO.detectavi(s) --> false
301+
end
302+
open(joinpath(file_dir, "magic1.tiff")) do s
303+
@fact FileIO.detectavi(s) --> false
304+
end
305+
q = query(joinpath(file_dir, "bees.avi"))
306+
@fact typeof(q) --> File{format"AVI"}
307+
end

0 commit comments

Comments
 (0)