# Path: pyhindsight/lib/ccl_chrome_indexeddb/ccl_simplesnappy.py
# DEBUG = False
# def log(msg):
# def _read_le_varint(stream: typing.BinaryIO) -> typing.Optional[typing.Tuple[int, bytes]]:
# def read_le_varint(stream: typing.BinaryIO) -> typing.Optional[int]:
# def read_uint16(stream: typing.BinaryIO) -> int:
# def read_uint24(stream: typing.BinaryIO) -> int:
# def read_uint32(stream: typing.BinaryIO) -> int:
# def read_byte(stream: typing.BinaryIO) -> typing.Optional[int]:
# def decompress(data: typing.BinaryIO) -> bytes:
# def main(path):
# class ElementType(enum.IntEnum):


import typing
import struct
import re
import os
import io
import pathlib
import dataclasses
import enum
from collections import namedtuple
from types import MappingProxyType
from pyhindsight.lib.ccl_chrome_indexeddb import ccl_simplesnappy

        self._f = file.open("rb")
        self._f.seek(-LdbFile.FOOTER_SIZE, os.SEEK_END)

        self._meta_index_handle = BlockHandle.from_stream(self._f)
        self._index_handle = BlockHandle.from_stream(self._f)
        self._f.seek(-8, os.SEEK_END)
        magic, = struct.unpack("<Q", self._f.read(8))
        if magic != LdbFile.MAGIC:
            raise ValueError(f"Invalid magic number in {file}")

        self._index = self._read_index()

    def _read_block(self, handle: BlockHandle):
        # block is the size in the blockhandle plus the trailer
        # the trailer is 5 bytes long.
        # idx  size  meaning
        # 0    1     CompressionType (0 = none, 1 = snappy)
        # 1    4     CRC32

        self._f.seek(handle.offset)
        raw_block = self._f.read(handle.length)
        trailer = self._f.read(LdbFile.BLOCK_TRAILER_SIZE)

        if len(raw_block) != handle.length or len(trailer) != LdbFile.BLOCK_TRAILER_SIZE:
            raise ValueError(f"Could not read all of the block at offset {handle.offset} in file {self.path}")

        is_compressed = trailer[0] != 0
        if is_compressed:
            with io.BytesIO(raw_block) as buff:

# Path: pyhindsight/lib/ccl_chrome_indexeddb/ccl_simplesnappy.py
# DEBUG = False
# def log(msg):
# def _read_le_varint(stream: typing.BinaryIO) -> typing.Optional[typing.Tuple[int, bytes]]:
# def read_le_varint(stream: typing.BinaryIO) -> typing.Optional[int]:
# def read_uint16(stream: typing.BinaryIO) -> int:
# def read_uint24(stream: typing.BinaryIO) -> int:
# def read_uint32(stream: typing.BinaryIO) -> int:
# def read_byte(stream: typing.BinaryIO) -> typing.Optional[int]:
# def decompress(data: typing.BinaryIO) -> bytes:
# def main(path):
# class ElementType(enum.IntEnum):


# Path: pyhindsight/lib/ccl_chrome_indexeddb/ccl_leveldb.py
import typing
import struct
import re
import os
import io
import pathlib
import dataclasses
import enum
from collections import namedtuple
from types import MappingProxyType
from pyhindsight.lib.ccl_chrome_indexeddb import ccl_simplesnappy


        self._f = file.open("rb")
        self._f.seek(-LdbFile.FOOTER_SIZE, os.SEEK_END)

        self._meta_index_handle = BlockHandle.from_stream(self._f)
        self._index_handle = BlockHandle.from_stream(self._f)
        self._f.seek(-8, os.SEEK_END)
        magic, = struct.unpack("<Q", self._f.read(8))
        if magic != LdbFile.MAGIC:
            raise ValueError(f"Invalid magic number in {file}")

        self._index = self._read_index()

    def _read_block(self, handle: BlockHandle):
        # block is the size in the blockhandle plus the trailer
        # the trailer is 5 bytes long.
        # idx  size  meaning
        # 0    1     CompressionType (0 = none, 1 = snappy)
        # 1    4     CRC32

        self._f.seek(handle.offset)
        raw_block = self._f.read(handle.length)
        trailer = self._f.read(LdbFile.BLOCK_TRAILER_SIZE)

        if len(raw_block) != handle.length or len(trailer) != LdbFile.BLOCK_TRAILER_SIZE:
            raise ValueError(f"Could not read all of the block at offset {handle.offset} in file {self.path}")

        is_compressed = trailer[0] != 0
        if is_compressed:
            with io.BytesIO(raw_block) as buff:

                raw_block = ccl_simplesnappy.decompress(buff)