diff --git a/Project.toml b/Project.toml index 7c5967d887b..5b7a6c3dfb5 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,8 @@ version = "0.20.0" [deps] Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" +CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd" +CodecXz = "ba30903b-d9e8-5048-a5ec-d1f5b0d4b47b" CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" @@ -13,7 +15,6 @@ MathOptFormat = "f4570300-c277-12e8-125c-4912f86ce65d" MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/src/JuMP.jl b/src/JuMP.jl index 3bc3684e698..37791357741 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -17,6 +17,8 @@ import MathOptInterface const MOI = MathOptInterface const MOIU = MOI.Utilities using MathOptFormat +import CodecBzip2 +import CodecXz import CodecZlib import Calculus diff --git a/src/file_formats.jl b/src/file_formats.jl index f269992a91b..afe54e09804 100644 --- a/src/file_formats.jl +++ b/src/file_formats.jl @@ -22,11 +22,15 @@ end List of accepted export compression formats. `AUTOMATIC_FILE_COMPRESSION` corresponds to a detection from the file name. """ -@enum(FileCompression, NO_FILE_COMPRESSION, GZIP, AUTOMATIC_FILE_COMPRESSION) +@enum(FileCompression, NO_FILE_COMPRESSION, BZIP2, GZIP, XZ, AUTOMATIC_FILE_COMPRESSION) function _filename_to_compression(filename::String) - return if endswith(filename, ".gz") + return if endswith(filename, ".bz2") + BZIP2 + elseif endswith(filename, ".gz") GZIP + elseif endswith(filename, ".xz") + XZ else NO_FILE_COMPRESSION end @@ -37,8 +41,14 @@ function _open(f::Function, filename::String, mode::String; compression::FileCom compression = _filename_to_compression(filename) end - if compression == GZIP - stream = (mode == "r") ? CodecZlib.GzipDecompressorStream : CodecZlib.GzipCompressorStream + if compression == BZIP2 || compression == GZIP || compression == XZ + stream = if compression == BZIP2 + (mode == "r") ? CodecBzip2.Bzip2DecompressorStream : CodecBzip2.Bzip2CompressorStream + elseif compression == GZIP + (mode == "r") ? CodecZlib.GzipDecompressorStream : CodecZlib.GzipCompressorStream + else # compression == XZ + (mode == "r") ? CodecXz.XzDecompressorStream : CodecXz.XzCompressorStream + end return open(f, stream, filename, mode) else return open(f, filename, mode) @@ -77,8 +87,6 @@ function write_to_file(model::Model, filename::String; format::FileFormat=AUTOMA format = _filename_to_format(filename) end - # println((filename, "w", compression)) - _open(filename, "w", compression=compression) do io write_to_file(model, io, format; kwargs...) end