Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Blosc = "0.7.3"
CodecBzip2 = "0.7, 0.8"
ChunkCodecLibBzip2 = "0.3"
CodecLz4 = "0.4"
CodecZstd = "0.7, 0.8"
Compat = "3.1.0, 4"
Expand All @@ -30,7 +30,7 @@ julia = "1.9"

[extensions]
BloscExt = "Blosc"
CodecBzip2Ext = "CodecBzip2"
ChunkCodecLibBzip2Ext = "ChunkCodecLibBzip2"
CodecLz4Ext = "CodecLz4"
CodecZstdExt = "CodecZstd"
FileIOExt = "FileIO"
Expand All @@ -41,7 +41,6 @@ bitshuffle_jll_ext = "bitshuffle_jll"
[extras]
Blosc = "a74b3585-a348-5f62-a45c-50e91977d574"
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
CodecLz4 = "5ba52731-8f18-5e0d-9241-30f10d1ec561"
CodecZstd = "6b39b394-51ab-5f42-8807-6242bab2b4c2"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand All @@ -62,10 +61,10 @@ test = ["Test", "MPI", "Distributed", "LinearAlgebra", "OrderedCollections", "Pk

[weakdeps]
Blosc = "a74b3585-a348-5f62-a45c-50e91977d574"
CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
CodecLz4 = "5ba52731-8f18-5e0d-9241-30f10d1ec561"
CodecZstd = "6b39b394-51ab-5f42-8807-6242bab2b4c2"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
ChunkCodecLibBzip2 = "2b723af9-f480-4e8d-a1e4-4a9f5a906122"
bitshuffle_jll = "228fe19c-1b83-5282-a626-13744502a320"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using MPI # needed to generate docs for parallel HDF5 API
const BloscExt = Base.get_extension(HDF5, :BloscExt)
const bitshuffle_jll_ext = Base.get_extension(HDF5, :bitshuffle_jll_ext)
const BloscExt = Base.get_extension(HDF5, :BloscExt)
const CodecBzip2Ext = Base.get_extension(HDF5, :CodecBzip2Ext)
const ChunkCodecLibBzip2Ext = Base.get_extension(HDF5, :ChunkCodecLibBzip2Ext)
const CodecLz4Ext = Base.get_extension(HDF5, :CodecLz4Ext)
const CodecZstdExt = Base.get_extension(HDF5, :CodecZstdExt)

Expand Down
102 changes: 102 additions & 0 deletions ext/ChunkCodecLibBzip2Ext/ChunkCodecLibBzip2Ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#=
The code below has been ported to Julia from the original C source:
https://github.com/nexusformat/HDF5-External-Filter-Plugins/blob/master/BZIP2/src/H5Zbzip2.c
The filter function H5Z_filter_bzip2 was adopted from:
PyTables http://www.pytables.org.
The plugin can be used with the HDF5 library version 1.8.11+ to read HDF5 datasets compressed with bzip2 created by PyTables.
License: licenses/H5Zbzip2_LICENSE.txt

The following license applies to the Julia port.
Copyright (c) 2021 Mark Kittisopikul and Howard Hughes Medical Institute. License MIT, see LICENSE.txt
=#
module ChunkCodecLibBzip2Ext

using ChunkCodecLibBzip2:
BZ2Codec,
BZ2EncodeOptions
using ChunkCodecLibBzip2.ChunkCodecCore:
try_resize_decode!,
encode_bound,
try_encode!
using HDF5.API
import HDF5.Filters:
Filter, filterid, register_filter, filtername, filter_func, filter_cfunc, UnsafeBuffer

export H5Z_FILTER_BZIP2, H5Z_filter_bzip2, Bzip2Filter

const H5Z_FILTER_BZIP2 = API.H5Z_filter_t(307)
const bzip2_name = "HDF5 bzip2 filter; see http://www.hdfgroup.org/services/contributions.html"

function H5Z_filter_bzip2(
flags::Cuint,
cd_nelmts::Csize_t,
cd_values::Ptr{Cuint},
nbytes::Csize_t,
buf_size::Ptr{Csize_t},
buf::Ptr{Ptr{Cvoid}}
)::Csize_t
dst = UnsafeBuffer()
outdatalen::Csize_t = Csize_t(0)
try
src = UnsafeBuffer(unsafe_load(buf), nbytes)
if flags & API.H5Z_FLAG_REVERSE != 0
# Decompress
outbuflen = Int64(nbytes) * 3 + 1
resize!(dst, outbuflen)
outdatalen = Int64(try_resize_decode!(BZ2Codec(), dst, src, typemax(Int64)))
else
# Compress data
blockSize100k = 9
# Get compression blocksize if present
if cd_nelmts > 0
blockSize100k = unsafe_load(cd_values)
end
encoder = BZ2EncodeOptions(;blockSize100k)
# Prepare the output buffer
resize!(dst, encode_bound(encoder, Int64(nbytes)))
outdatalen = Int64(try_encode!(encoder, dst, src))
end # if flags & API.H5Z_FLAG_REVERSE != 0
resize!(src, Int64(0))
unsafe_store!(buf, dst.p)
unsafe_store!(buf_size, dst.size)
catch err
# "In the case of failure, the return value is 0 (zero) and all pointer arguments are left unchanged."
outdatalen = Csize_t(0)
resize!(dst, Int64(0))
@error "H5Zbzip2.jl Non-Fatal ERROR: " err
display(stacktrace(catch_backtrace()))
end # try - catch

return outdatalen
end # function H5Z_filter_bzip2

# Filters Module

"""
Bzip2Filter(blockSize100k)

Apply Bzip2 compression. The filter id is $H5Z_FILTER_BZIP2.

# External Links
* [BZIP2 HDF5 Filter ID 307](https://portal.hdfgroup.org/display/support/Filters#Filters-307)
* [PyTables Repository (C code)](https://github.com/PyTables/PyTables)
"""
struct Bzip2Filter <: Filter
blockSize100k::Cuint
end
Bzip2Filter() = Bzip2Filter(9)

filterid(::Type{Bzip2Filter}) = H5Z_FILTER_BZIP2
filtername(::Type{Bzip2Filter}) = bzip2_name
filter_func(::Type{Bzip2Filter}) = H5Z_filter_bzip2
filter_cfunc(::Type{Bzip2Filter}) = @cfunction(
H5Z_filter_bzip2,
Csize_t,
(Cuint, Csize_t, Ptr{Cuint}, Csize_t, Ptr{Csize_t}, Ptr{Ptr{Cvoid}})
)

function __init__()
register_filter(Bzip2Filter)
end

end # module CodecBzip2Ext
File renamed without changes.
File renamed without changes.
239 changes: 0 additions & 239 deletions ext/CodecBzip2Ext/CodecBzip2Ext.jl

This file was deleted.

Loading
Loading