def test_index_lzo_file_single_block(self):
        stream = self._lzo_stream(1)
        index = StringIO()

        lzo_indexer.index_lzo_file(stream, index)

        self.assertEqual(index.getvalue(), "\x00\x00\x00\x00\x00\x00\x00\x26")
Exemple #2
0
def indexer(force: bool, extension: str, file_name: str) -> bool:
    archive = Path(file_name)
    archive_index = archive.with_suffix(archive.suffix + extension)

    if archive.suffix not in SUFFIXES:
        click.echo(
            click.style(
                f"File {file_name} seems like not LZO archive, skip it",
                fg="yellow",
                bold=True))
        return False

    if archive_index.exists() and not force:
        click.echo(
            click.style(f"Index for {file_name} already exists",
                        fg="yellow",
                        bold=True))
        return False

    with archive.open(mode="rb") as f_in, archive_index.open(
            mode="wb") as f_out:
        index_lzo_file(f_in, f_out)

    click.echo(f"Created index for {click.style(file_name, bold=True)}")

    return True
    def test_index_lzo_file_single_block(self):
        stream = self._lzo_stream(1)
        index = StringIO()

        lzo_indexer.index_lzo_file(stream, index)

        self.assertEqual(index.getvalue(), "\x00\x00\x00\x00\x00\x00\x00\x26")
    def test_index_lzo_file_multiple_blocks(self):
        stream = self._lzo_stream(10**6)
        index = StringIO()

        lzo_indexer.index_lzo_file(stream, index)

        self.assertEqual(index.getvalue(), "\x00\x00\x00\x00\x00\x00\x00&\x00" \
                                           "\x00\x00\x00\x00\x00\x04\xd1\x00" \
                                           "\x00\x00\x00\x00\x00\t|\x00\x00" \
                                           "\x00\x00\x00\x00\x0e'")
    def test_index_lzo_file_multiple_blocks(self):
        stream = self._lzo_stream(10**6)
        index = StringIO()

        lzo_indexer.index_lzo_file(stream, index)

        self.assertEqual(index.getvalue(), "\x00\x00\x00\x00\x00\x00\x00&\x00" \
                                           "\x00\x00\x00\x00\x00\x04\xd1\x00" \
                                           "\x00\x00\x00\x00\x00\t|\x00\x00" \
                                           "\x00\x00\x00\x00\x0e'")