Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: creating size-limited tar files Date: 7 Nov 2012 18:40:14 GMT Organization: Norwich University Lines: 28 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net 2aB5WOHnwDBZ4Q2k3U30OwFrF6oVN6riEetYbwIImdB25yzwb38FyoRu06kNxcIUR0 Cancel-Lock: sha1:B0BvUms23y4oQ6I/kW6cS/jHYEg= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: csiph.com comp.lang.python:32903 On 2012-11-07, andrea crotti wrote: > Simple problem, given a lot of data in many files/directories, I > should create a tar file splitted in chunks <= a given size. > > The simplest way would be to compress the whole thing and then split. > > At the moment the actual script which I'm replacing is doing a > "system('split..')", which is not that great, so I would like to do it > while compressing. > > So I thought about (in pseudocode) > > while remaining_files: > tar_file.addfile(remaining_files.pop()) > if size(tar_file) >= limit: > close(tar_file) > tar_file = new_tar_file() > I have not used this module before, but what you seem to be asking about is: TarFile.gettarinfo().size But your algorithm stops after the file is already too big. -- Neil Cerutti