Skip to main content

A user-friendly interface for handling files, archives, and compressed files in Python

Project description

filepack

A user-friendly interface for handling files, archives, and compressed files in Python.

Features

  • User-friendly interface for common file operations.
  • Support for various archive types: TAR, ZIP, RAR, SEVEN_ZIP.
  • Support for various compression types: GZIP, BZ2, LZ4, XZ.

Installation

pip install filepack

API Overview

FilePack

Method/Property Description
path Returns the path of the file.
suffix Returns the file's suffix.
is_compressed Check if the file is compressed.
uncompressed_size Get uncompressed size.
compressed_size Get compressed size.
compression_ratio Get compression ratio.
compress Compress the file.
decompress Decompress the file.

Archive

Method/Property Description
path Returns the path of the archive.
suffix Returns the archive's suffix.
extract_member Extract a specific member.
get_member Get member's metadata
get_members Get a list of members metadata.
add_member Add a member to the archive.
remove_member Remove a member from the archive.
extract_all Extract all members.
remove_all Remove all members from the archive.
print_members Print all members.

Compression

Method/Property Description
path Returns the path of the compressed file.
suffix Returns the file's suffix.
uncompressed_size Get uncompressed size.
compressed_size Get compressed size.
compression_ratio Get compression ratio.
compress Compress the file.
decompress Decompress the file.
is_compressed Check if the file is compressed.

Usage

Working with Archives

from filepack import FilePack


# if the given path can exist or not yet, but must refer to an archive.
file_pack = FilePack("path/to/your/archive/file")

# Extract a specific member
archive.extract_member(target_path="path/to/target/directory")

# Get a list of members
members = archive.get_members()

# Add a member to the archive
archive.add_member("path/to/member")

# Remove a member from the archive
archive.remove_member("name_of_member")

# Extract all members
archive.extract_all(target_path="path/to/target")

# Remove all members from the archive
archive.remove_all()

# Print all members
archive.print_members()

Working with Compressions

from filepack import FilePack


# if the given path must exist, but can refer to a file which is compressed already or not.
file_pack = FilePack("path/to/your/existed/file")

# Compressed or not
is_compressed = file_pack.is_compressed(compression_algorithm="gz")

# Get uncompressed size
size = file_pack.uncompressed_size(compression_algorithm="gz")

# Compress and decompress files in place
new_path = file_pack.compress(compression_algorithm="gz") # with .gz
new_path = file_pack.decompress(compression_algorithm="gz") # without .gz

# Compress and decompress files into a different path
new_path = file_pack.compress(target_path="path/to/compressed/file", compression_algorithm="gz")
new_path = file_pack.decompress(target_path="path/to/uncompressed/file", compression_algorithm="gz")

Working with Both

from filepack import FilePack


file_pack = FilePack("path/to/your/archive/file")

archive.add_member("path/to/member")
new_path = file_pack.compress(compression_algorithm="gz")

Error Handling

filepack has built-in error handling mechanisms. It raises user-friendly exceptions for common errors, allowing you to handle them gracefully in your application.

Contributing

Interested in contributing to filepack? See our contribution guide.

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

filepack-0.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

filepack-0.1.0-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file filepack-0.1.0.tar.gz.

File metadata

  • Download URL: filepack-0.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for filepack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 068a420a7fc9d4a96033fe6cc0a790640c8b1cfb6a8f34c24791c368e55bc450
MD5 5ba28cc833b3a787c25288c34661ac5d
BLAKE2b-256 2eeff061e9345ca8c9c650c75530d1c750648464256b1fb50eb474d5aefc9e64

See more details on using hashes here.

File details

Details for the file filepack-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: filepack-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for filepack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3238971612068cdd8ff621b859a01b5ec54e3568e5c8d3440b0cd9a653a4b2bd
MD5 8c735c13c93fe3570191cfde17821b88
BLAKE2b-256 ee8c07146f4b4f19a756ba52ccbb109e543908438a43e187aa2b712b9d5048e9

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