Skip to content

Commit

Permalink
Preserve out_buffer in process()
Browse files Browse the repository at this point in the history
  • Loading branch information
kpamnany committed Nov 3, 2023
1 parent f1cf8f8 commit db79d9c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/lz4_compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,20 @@ function TranscodingStreams.process(
out_buffer = Vector{UInt8}(undef, LZ4_compressBound(data_size))
unsafe_copyto!(in_buffer, input.ptr, data_size)

compressed_size = LZ4_compress_fast_continue(
codec.streamptr,
in_buffer,
pointer(out_buffer),
data_size,
length(out_buffer),
codec.acceleration,
)

checkbounds(output, compressed_size + CINT_SIZE)
writeint(output, compressed_size)
unsafe_copyto!(output.ptr + CINT_SIZE, pointer(out_buffer), compressed_size)
GC.@preserve out_buffer begin
compressed_size = LZ4_compress_fast_continue(
codec.streamptr,
in_buffer,
pointer(out_buffer),
data_size,
length(out_buffer),
codec.acceleration,
)

checkbounds(output, compressed_size + CINT_SIZE)
writeint(output, compressed_size)
unsafe_copyto!(output.ptr + CINT_SIZE, pointer(out_buffer), compressed_size)
end

return (data_size, compressed_size + CINT_SIZE, :ok)
catch err
Expand Down

0 comments on commit db79d9c

Please sign in to comment.