Skip to main content

Write and read tape archives (tar) sequentially.

Project description

TestStatus PyPiStatus BlackStyle BlackPackStyle MITLicenseBadge

A wrapper around tarfile which is deliberatly limited and simple. The package sequential_tar is meant to ease the writing and reading of tarfiles where the payload of the files within the tarfile is maent to go through the program’s memory. Here, only regular files can be written to a tarfile and blocks different from regular files are ignored while reading. This package is a good start when one plans to use tarfiles as containers for programs to read data from directly into their memory without seeking or the creation of temporary files.

modes

When writing the next file to the tarfile, one can set the mode to choose either text "t" or binary "b". Further a compression can be applied by adding "|gz" to the mode. In the same manner, a mode can be set when reading a file from the tarfile. This way, possible decompression and text/binary conversions can be taken care of with just a few characters in the mode parameter.

import sequential_tar as seqtar
import os
path = "test.tar"

Set the mode for each file while writing to the tarfile.

with seqtar.open(path, "w") as tar:
    tar.write(
        name="1.txt",
        payload="I am text number 1.",
        mode="wt",
    )
    tar.write(
        name="2.txt.gz",
        payload="I am text number 2.",
        mode="wt|gz",
    )
    tar.write(
        name="3.bin.gz",
        payload=b"0123456789",
        mode="wb|gz",
    )
    tar.write(
        name="4.bin",
        payload=b"123-123-123-123-123-123-123",
        mode="wb",
    )

Set the mode for each file while reading from the tarfile.

with seqtar.open(path, "r") as tar:
    item = next(tar)
    assert item.name == "1.txt"
    assert item.read(mode="rt") == "I am text number 1."

    item = next(tar)
    assert item.name == "2.txt.gz"
    assert item.read(mode="rt|gz") == "I am text number 2."

    item = next(tar)
    assert item.name == "3.bin.gz"
    assert item.read(mode="rb|gz") == b"0123456789"

    item = next(tar)
    assert item.name == "4.bin"
    assert item.read(mode="rb") == b"123-123-123-123-123-123-123"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sequential_tar-0.0.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

sequential_tar-0.0.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file sequential_tar-0.0.4.tar.gz.

File metadata

  • Download URL: sequential_tar-0.0.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for sequential_tar-0.0.4.tar.gz
Algorithm Hash digest
SHA256 53f99cfe7c6790ae850e7db3a0d14def945093d80059809821a4be56276a4e3c
MD5 fe3c52ddee7a3f40de42d4ddaf84d138
BLAKE2b-256 84d12b41419e1c5862c5300b5fd0c2379befa0e422fad581541cd2d9c4db816a

See more details on using hashes here.

File details

Details for the file sequential_tar-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for sequential_tar-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 12f6ee4edf591bb0112c49e23bf4c0c4c1ae829337b2a9b742d5a31ed04afd1f
MD5 7c39a6644868e4f200d9754017d872b0
BLAKE2b-256 cd3873da7d67a75170cb6c39cf994a3c2262aa1732e2ab1a02638ebc461a4bf4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page