From d2d8122daafc87b47e60ae311a03c28050ca4f73 Mon Sep 17 00:00:00 2001 From: nhz2 Date: Mon, 24 Aug 2026 15:21:39 -0400 Subject: [PATCH] Remove Libz --- src/registry.jl | 29 +++++++++++++---------------- test/loadsave.jl | 4 ---- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/registry.jl b/src/registry.jl index a5575f5..ab6a115 100644 --- a/src/registry.jl +++ b/src/registry.jl @@ -77,6 +77,12 @@ detect_compressed(io, len=getlength(io); kwargs...) = detect_compressor(io, len; const compressed_fits_exten = r"\.(fit|fits|fts|FIT|FITS|FTS)\.(gz|GZ)\>" name_matches_compressed_fits(io) = (:name ∈ propertynames(io)) && endswith(io.name, compressed_fits_exten) +# We only fall back to treating a bare +# compressed stream as RData when the filename actually carries an RData +# extension; otherwise `detect_rdata` would claim any compressed file. +const rdata_exten = r"\.(rda|RData|rdata)\>" +name_matches_rdata(io) = (:name ∈ propertynames(io)) && endswith(io.name, rdata_exten) + # test for RD?n magic sequence at the beginning of R data input stream function detect_rdata(io) seekstart(io) @@ -98,11 +104,14 @@ function detect_rdata(io) return true end checked_match(io) && return true - return detect_compressed(io; formats=["GZIP", "BZIP2", "XZ"]) && !name_matches_compressed_fits(io) + return name_matches_rdata(io) && detect_compressed(io; formats=["GZIP", "BZIP2", "XZ"]) end add_format(format"RData", detect_rdata, [".rda", ".RData", ".rdata"], [idRData, LOAD]) +const rdata_single_exten = r"\.rds\>" +name_matches_rdata_single(io) = (:name ∈ propertynames(io)) && endswith(io.name, rdata_single_exten) + function detect_rdata_single(io) seekstart(io) function checked_match(io) @@ -119,12 +128,14 @@ function detect_rdata_single(io) res = checked_match(io) if !res - res = detect_compressed(io; formats=["GZIP", "BZIP2", "XZ"]) && !name_matches_compressed_fits(io) + res = name_matches_rdata_single(io) && detect_compressed(io; formats=["GZIP", "BZIP2", "XZ"]) end seekstart(io) return res end +add_format(format"RDataSingle", detect_rdata_single, [".rds"], [idRData, LOAD]) + function detect_excel(io) # All OOXML Excel files are ZIPs starting with PK\x03\x04 magic = try @@ -138,8 +149,6 @@ function detect_excel(io) # so just claiming the ZIP magic is sufficient to beat NPZ. end -add_format(format"RDataSingle", detect_rdata_single, [".rds"], [idRData, LOAD]) - add_format(format"AVSfld", "# AVS", [".fld"], [idAVSfldIO]) add_format(format"CSV", (), [".csv"], [idCSVFiles]) add_format(format"TSV", (), [".tsv"], [idCSVFiles]) @@ -507,18 +516,6 @@ end add_format(format"STL_ASCII", detect_stlascii, [".stl", ".STL"], [idMeshIO]) add_format(format"STL_BINARY", detect_stlbinary, [".stl", ".STL"], [idMeshIO]) -# GZip has two simple magic bytes [0x1f, 0x8b] but we don't want to dispatch to Libz -# for file extensions like .fits.gz -function detect_gzip(io) - if name_matches_compressed_fits(io) - return false - end - getlength(io) >= 2 || return false - magic = read!(io, Vector{UInt8}(undef, 2)) - return magic == [0x1f, 0x8b] -end -add_format(format"GZIP", detect_gzip, ".gz", [:Libz => UUID("2ec943e9-cfe8-584d-b93d-64dcb6d567b7")]) - # Astro Data # FITS files are often gziped and given the extension ".fits.gz". We want to load those directly and not dispatch to Libz diff --git a/test/loadsave.jl b/test/loadsave.jl index 6149373..2b0610f 100644 --- a/test/loadsave.jl +++ b/test/loadsave.jl @@ -8,7 +8,6 @@ module TestLoadSave load(file::File{format"PBMText"}) = "PBMText" load(file::File{format"PBMBinary"}) = "PBMBinary" load(file::File{format"JLD"}) = "JLD" - load(file::File{format"GZIP"}) = "GZIP" end module TestLoadSave2 import FileIO: File, @format_str @@ -33,7 +32,6 @@ end add_loader(format"PBMBinary", TestLoadSave) add_loader(format"HDF5", TestLoadSave2) add_loader(format"JLD", TestLoadSave) - add_loader(format"GZIP", TestLoadSave) add_loader(format"BIB", TestLoadSave2) add_loader(format"DCM", TestLoadSave2) @@ -51,8 +49,6 @@ end @test load(joinpath(fp,"file2.h5")) == "HDF5" # JLD file saved with .jld extension @test load(joinpath(fp,"file.jld")) == "JLD" - # GZIP file saved with .gz extension - @test load(joinpath(fp,"file.csv.gz")) == "GZIP" # Bibliography file saved with .bib extension @test load(joinpath(fp,"file.bib")) == "BIB" # DICOM file saved with .dcm extension