Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lzma documentation: example to XZ compress file on disk #76341

Open
dhimmel mannequin opened this issue Nov 28, 2017 · 2 comments
Open

lzma documentation: example to XZ compress file on disk #76341

dhimmel mannequin opened this issue Nov 28, 2017 · 2 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir topic-IO type-feature A feature request or enhancement

Comments

@dhimmel
Copy link
Mannequin

dhimmel mannequin commented Nov 28, 2017

BPO 32160
Nosy @dhimmel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2017-11-28.20:41:15.049>
labels = ['3.8', 'type-feature', '3.7', 'expert-IO', 'docs']
title = 'lzma documentation: example to XZ compress file on disk'
updated_at = <Date 2017-11-28.20:50:25.989>
user = 'https://github.com/dhimmel'

bugs.python.org fields:

activity = <Date 2017-11-28.20:50:25.989>
actor = 'dhimmel'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation', 'IO']
creation = <Date 2017-11-28.20:41:15.049>
creator = 'dhimmel'
dependencies = []
files = []
hgrepos = []
issue_num = 32160
keywords = []
message_count = 2.0
messages = ['307163', '307166']
nosy_count = 2.0
nosy_names = ['docs@python', 'dhimmel']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue32160'
versions = ['Python 3.7', 'Python 3.8']

@dhimmel
Copy link
Mannequin Author

dhimmel mannequin commented Nov 28, 2017

The documentation for the lzma module currently contains 6 examples (https://docs.python.org/3.6/library/lzma.html#examples). However, it does not include an example to XZ compress a file on disk. The functionality I'm envisioning would be similar to the command:

xz --compress --keep path

I believe this is possible in python with:

with open(in_path) as in_file, lzma.open(out_path, 'w') as out_file:
    shutil.copyfileobj(in_path, out_file)

Note gzip has a similar example (https://docs.python.org/3.6/library/gzip.html#examples-of-usage).

Compressing an existing file on disk is a use case I commonly encounter. Python is ideal for the task because it provides a cross-platform solution that doesn't require installing additional command line utilities. Before finding shutil.copyfileobj, I assumed memory-efficient on-disk XZ compression was not possible in Python, due to its omission from the docs.

I'm happy to propose example code for the documentation.

Alternatively, if this feature is considered useful, we could consider an API addition to provide a one-line command for on-disk compressing/decompressing files. Since this would be a major addition that should be consistent across compression modules, perhaps we should just start with a lzma doc example?

@dhimmel dhimmel mannequin added 3.7 (EOL) end of life 3.8 only security fixes topic-IO docs Documentation in the Doc dir labels Nov 28, 2017
@dhimmel dhimmel mannequin assigned docspython Nov 28, 2017
@dhimmel dhimmel mannequin added the type-feature A feature request or enhancement label Nov 28, 2017
@dhimmel
Copy link
Mannequin Author

dhimmel mannequin commented Nov 28, 2017

we could consider an API addition

Just brainstorming here... perhaps an API addition would be most appropriate in the shutil module (https://docs.python.org/3.6/library/shutil.html) which already contains shutil.make_archive and shutil.unpack_archive. One could imagine shutil.compress and shutil.decompress that took a format argument to specify the compression type.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir topic-IO type-feature A feature request or enhancement
Projects
Status: No status
Development

No branches or pull requests

0 participants