Skip to content
Snippets Groups Projects
Commit 1387547d authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

retry under bz2

parent b548d41f
No related branches found
No related tags found
No related merge requests found
import gzip
import bz2
import io
import os
import threading
......@@ -28,15 +28,12 @@ cdef class AlternativeMMap:
def madvise(self, a, b, c):
...
def resize(self, file_size: int):
def resize(self, int file_size):
self.size = file_size
def __init__(self, io_file: io.BinaryIO, file_lock_object):
self.io = io_file
if isinstance(io_file, gzip.GzipFile):
self.size = self.io.size
else:
self.io.seek(self.file_size, 0)
self.io.seek(0, 2)
self.size = self.io.tell()
self.file_lock_object = file_lock_object
......
import bz2
import gzip
import os
import typing as tp
import struct
import warnings
......@@ -58,7 +60,7 @@ cdef class DirectChunk(Chunk):
cpdef object open_file(self, str path):
if self.gzip:
return gzip.open(path, 'wb+', compresslevel=self.gzip)
return bz2.BZ2File(path, 'rb+', compresslevel=self.gzip)
else:
return super().open_file(path)
......@@ -66,16 +68,13 @@ cdef class DirectChunk(Chunk):
return 0
cpdef int after_init(self) except -1:
if isinstance(self.file, gzip.GzipFile):
self.file_size = self.file.size
else:
self.io.seek(0, 2)
self.file_size = self.file.tell()
self.file.seek(0, os.SEEK_END)
self.file_size = self.file.tell()
self.entries = (self.file_size - HEADER_SIZE) // self.block_size_plus
self.pointer = self.file_size
d = (self.file_size - self.block_size) - (self.file_size-self.block_size_plus)
cdef bytes b = self.mmap[self.file_size-self.block_size_plus:self.file_size-self.block_size]
print(self.file, d, repr(b))
self.max_ts, = STRUCT_Q.unpack(b)
return 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment