Last active
October 15, 2021 00:18
-
-
Save CiaranOMara/2baec491c4c3f2cebcf74d8b4d6ecc6a to your computer and use it in GitHub Desktop.
BGZFStreams issue #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Pkg | |
Pkg.activate(".") | |
Pkg.add(url="https://github.com/CiaranOMara/BGZFStreams.jl#develop") | |
using BGZFStreams | |
# Overwrite | |
@inline function BGZFStreams.ensure_buffered_data(stream) | |
#@assert stream.mode == READ_MODE | |
@label doit | |
while stream.block_index ≤ lastindex(stream.blocks) | |
@inbounds block = stream.blocks[stream.block_index] | |
if BGZFStreams.is_eof_block(block.compressed_block) # Note: `read_blocks!` does not necessarily fill/overwrite blocks till `lastindex(stream.blocks)`, we need to stop incrementing `stream.block_index` when an eof block is encountered. | |
break | |
end | |
if block.position ≤ block.size | |
return stream.block_index | |
end | |
stream.block_index += 1 | |
end | |
if !BGZFStreams.eof(stream.io) | |
BGZFStreams.read_blocks!(stream) | |
@goto doit | |
end | |
return 0 | |
end | |
n = 6 | |
i = mod(n, 1:Threads.nthreads()) | |
data = rand(0x00:0xf0, (n-1)*(BGZFStreams.BGZF_MAX_BLOCK_SIZE - 256) + 2) | |
# Setup buffer | |
buffer = IOBuffer() | |
stream = BGZFStream(buffer, "w") | |
stream.onclose = io -> nothing # HACK: do not close the buffer after the stream is closed | |
write(stream, data) | |
close(stream) | |
seekstart(buffer) | |
stream = BGZFStream(buffer) | |
@info "Environment" Threads.nthreads() length(stream.blocks) | |
offsets = BGZFStreams.VirtualOffset[] | |
while !eof(stream) | |
push!(offsets, virtualoffset(stream)) | |
read(stream, UInt8) | |
end | |
println("Last offsets: ", offsets[end-n-1:end]) | |
println("block_offset: ", map(b->b.block_offset, stream.blocks)) | |
println("position: ", map(b->b.position, stream.blocks)) | |
println("size: ", map(b->b.size, stream.blocks)) | |
println("is_eof_block: ", map(b->BGZFStreams.is_eof_block(b.compressed_block), stream.blocks)) | |
println("virtualoffset(stream): ", virtualoffset(stream)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment