@@ -24,7 +24,6 @@ add_format(format"JLD", (unsafe_wrap(Vector{UInt8}, "Julia data file (HDF5), ver
24
24
unsafe_wrap (Vector{UInt8}, " Julia data file (HDF5), version 0.1" )), " .jld" , [:JLD => UUID (" 4138dd39-2aa7-5051-a626-17a0bb65d9c8" )])
25
25
add_format (format " JLD2" , (unsafe_wrap (Vector{UInt8}," Julia data file (HDF5), version 0.2" ),
26
26
unsafe_wrap (Vector{UInt8}, " HDF5-based Julia Data Format, version " )), " .jld2" , [:JLD2 => UUID (" 033835bb-8acc-5ee8-8aae-3f567f8a3819" )])
27
- add_format (format " GZIP" , [0x1f , 0x8b ], " .gz" , [:Libz => UUID (" 2ec943e9-cfe8-584d-b93d-64dcb6d567b7" )])
28
27
add_format (format " BSON" ,()," .bson" , [:BSON => UUID (" fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" )])
29
28
add_format (format " JLSO" , (), " .jlso" , [:JLSO => UUID (" 9da8a3cd-07a3-59c0-a743-3fdc52c30d11" )])
30
29
add_format (format " NPY" , " \x 93NUMPY" , " .npy" , [idNPZ])
60
59
61
60
detect_compressed (io, len= getlength (io); kwargs... ) = detect_compressor (io, len; kwargs... ) != = nothing
62
61
62
+ const compressed_fits_exten = r" \. (fit|fits|fts|FIT|FITS|FTS)\. (gz|GZ)\> "
63
+ name_matches_compressed_fits (io) = (:name ∈ propertynames (io)) && endswith (io. name, compressed_fits_exten)
64
+
63
65
# test for RD?n magic sequence at the beginning of R data input stream
64
66
function detect_rdata (io)
65
67
seekstart (io)
@@ -81,7 +83,7 @@ function detect_rdata(io)
81
83
return true
82
84
end
83
85
checked_match (io) && return true
84
- return detect_compressed (io; formats= [" GZIP" , " BZIP2" , " XZ" ])
86
+ return detect_compressed (io; formats= [" GZIP" , " BZIP2" , " XZ" ]) && ! name_matches_compressed_fits (io)
85
87
end
86
88
87
89
add_format (format " RData" , detect_rdata, [" .rda" , " .RData" , " .rdata" ], [idRData, LOAD])
@@ -102,7 +104,7 @@ function detect_rdata_single(io)
102
104
103
105
res = checked_match (io)
104
106
if ! res
105
- res = detect_compressed (io; formats= [" GZIP" , " BZIP2" , " XZ" ])
107
+ res = detect_compressed (io; formats= [" GZIP" , " BZIP2" , " XZ" ]) && ! name_matches_compressed_fits (io)
106
108
end
107
109
seekstart (io)
108
110
return res
@@ -463,11 +465,39 @@ end
463
465
add_format (format " STL_ASCII" , detect_stlascii, [" .stl" , " .STL" ], [idMeshIO])
464
466
add_format (format " STL_BINARY" , detect_stlbinary, [" .stl" , " .STL" ], [idMeshIO])
465
467
468
+ # GZip has two simple magic bytes [0x1f, 0x8b] but we don't want to dispatch to Libz
469
+ # for file extensions like .fits.gz
470
+ function detect_gzip (io)
471
+ if name_matches_compressed_fits (io)
472
+ return false
473
+ end
474
+ getlength (io) >= 2 || return false
475
+ magic = read! (io, Vector {UInt8} (undef, 2 ))
476
+ return magic == [0x1f , 0x8b ]
477
+ end
478
+ add_format (format " GZIP" , detect_gzip, " .gz" , [:Libz => UUID (" 2ec943e9-cfe8-584d-b93d-64dcb6d567b7" )])
479
+
480
+
466
481
# Astro Data
482
+ # FITS files are often gziped and given the extension ".fits.gz". We want to load those directly and not dispatch to Libz
483
+ function detect_fits (io)
484
+ # FITS files can have
485
+ if name_matches_compressed_fits (io)
486
+ return true
487
+ end
488
+ getlength (io) >= 30 || return false
489
+ magic = read! (io, Vector {UInt8} (undef, 30 ))
490
+ return magic == [0x53 ,0x49 ,0x4d ,0x50 ,0x4c ,0x45 ,0x20 ,0x20 ,0x3d ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x54 ]
491
+ end
467
492
add_format (format " FITS" ,
468
- # See https://www.loc.gov/preservation/digital/formats/fdd/fdd000317.shtml#sign
469
- [0x53 ,0x49 ,0x4d ,0x50 ,0x4c ,0x45 ,0x20 ,0x20 ,0x3d ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x54 ],
470
- [" .fit" , " .fits" , " .fts" , " .FIT" , " .FITS" , " .FTS" ], [:FITSIO => UUID (" 525bcba6-941b-5504-bd06-fd0dc1a4d2eb" )])
493
+ # See https://www.loc.gov/preservation/digital/formats/fdd/fdd000317.shtml#sign
494
+ # [0x53,0x49,0x4d,0x50,0x4c,0x45,0x20,0x20,0x3d,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x54],
495
+ detect_fits,
496
+ [" .fit" , " .fits" , " .fts" , " .FIT" , " .FITS" , " .FTS" , " .fit" ,],
497
+ [:FITSIO => UUID (" 525bcba6-941b-5504-bd06-fd0dc1a4d2eb" )],
498
+ [:AstroImages => UUID (" fe3fc30c-9b16-11e9-1c73-17dabf39f4ad" )])
499
+
500
+
471
501
472
502
function detect_gadget2 (io)
473
503
pos = position (io)
0 commit comments