Tarfile .bz2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jordan

    #1

    Tarfile .bz2

    When using python to create a tar.bz2 archive, and then using winrar to
    open the archive, it can't tell what the compressed size of each
    individual file in the archive is. Is this an issue with winrar or is
    there something that needs to be set when making the archive that isn't
    there by default.

    example archive:
    #Note, the tabs on this are not really tabs, so good luck copying it
    correctly

    import os, tarfile
    archive = tarfile.open("a rchive.tar.bz2" ,"w:bz2")
    for thing in os.listdir(some path):
    nthing = somepath+thing
    if os.path.isfile( nthing): # somepath must end in "\\" for this to
    work
    info = archive.gettari nfo(nthing)
    archive.addfile (info,file(nthi ng,'rb'))
    archive.close()
    ---

    Thanks,
    Jordan

  • Martin v. Löwis

    #2
    Re: Tarfile .bz2

    Jordan schrieb:
    When using python to create a tar.bz2 archive, and then using winrar to
    open the archive, it can't tell what the compressed size of each
    individual file in the archive is. Is this an issue with winrar or is
    there something that needs to be set when making the archive that isn't
    there by default.
    I believe it's an issue of the file format (tar.bz2). You don't compress
    individual files, but you compress the entire tar file. So it is not
    meaningful to talk about the compressed size of an individual archive
    member - they are all uncompressed.

    Regards,
    Martin

    Comment

    • Wolfgang Draxinger

      #3
      Re: Tarfile .bz2

      Jordan wrote:
      When using python to create a tar.bz2 archive, and then using
      winrar to open the archive, it can't tell what the compressed
      size of each
      individual file in the archive is. Is this an issue with
      winrar or is there something that needs to be set when making
      the archive that isn't there by default.
      When compressing a tar archive all files in the archive are
      compressed as a whole, i.e. you can only specify a compression
      ration for the whole archive and not just for a single file.

      Technically a tar.bz2 is actually a aggregation of multiple files
      into a single tar file, which is then compressed.

      This is different to e.g. PKZip in which each file is compressed
      individually and the compressed files are then merged into an
      archive.

      The first method has better compression ratio, since redundancies
      among files are compressed, too, whereas the latter is better if
      you need random access to the individual files.

      Wolfgang Draxinger
      --
      E-Mail address works, Jabber: hexarith@jabber .org, ICQ: 134682867

      Comment

      • Jordan

        #4
        Re: Tarfile .bz2

        So that would explain why a tar.bz2 archive can't be appended to
        wouldn't it... And also explain why winrar was so slow to open it (not
        something I mentioned before, but definitely noticed). I had wondered
        what it was that made bz2 so much better at compression than zip and
        rar. Not really on topic anymore but what's the method for tar.gz? And
        even more off the topic, does anyone know a good lossless compression
        method for images (mainly .jpg and .png)?

        Cheers,
        Jordan


        Wolfgang Draxinger wrote:
        Jordan wrote:
        >
        When using python to create a tar.bz2 archive, and then using
        winrar to open the archive, it can't tell what the compressed
        size of each
        individual file in the archive is. Is this an issue with
        winrar or is there something that needs to be set when making
        the archive that isn't there by default.
        >
        When compressing a tar archive all files in the archive are
        compressed as a whole, i.e. you can only specify a compression
        ration for the whole archive and not just for a single file.
        >
        Technically a tar.bz2 is actually a aggregation of multiple files
        into a single tar file, which is then compressed.
        >
        This is different to e.g. PKZip in which each file is compressed
        individually and the compressed files are then merged into an
        archive.
        >
        The first method has better compression ratio, since redundancies
        among files are compressed, too, whereas the latter is better if
        you need random access to the individual files.
        >
        Wolfgang Draxinger
        --
        E-Mail address works, Jabber: hexarith@jabber .org, ICQ: 134682867

        Comment

        • Martin v. Löwis

          #5
          Re: Tarfile .bz2

          Jordan schrieb:
          Not really on topic anymore but what's the method for tar.gz?
          It works like .tar.bz2, except that it uses gzip (www.gzip.org)
          as the compression library. The underlying compression algorithm
          is LZW.
          And
          even more off the topic, does anyone know a good lossless compression
          method for images (mainly .jpg and .png)?
          Well, .jpg files are already compressed in a lossy way (.jpg is
          inherently lossy); to compress it further, you need to increase
          the loss. PNG is also compressed already, see

          A user-friendly introduction to PNG image format.


          The compression algorithm inside PNG is zlib (which is the same
          as the gzip algorithm). Perhaps you should read the comp.compressio n
          FAQ:

          http://www.faqs.org/faqs/compression-faq/

          Regards,
          Martin

          Comment

          • Yu-Xi Lim

            #6
            Re: Tarfile .bz2

            Jordan wrote:
            So that would explain why a tar.bz2 archive can't be appended to
            wouldn't it... And also explain why winrar was so slow to open it (not
            something I mentioned before, but definitely noticed). I had wondered
            what it was that made bz2 so much better at compression than zip and
            rar. Not really on topic anymore but what's the method for tar.gz? And
            even more off the topic, does anyone know a good lossless compression
            method for images (mainly .jpg and .png)?
            You can get the same effect from RAR and other formats (ACE, 7z) by
            using the "Solid Archive" or similar option. Ideally, you'd be
            compressing lots of similar files for this to be effective. The actual
            compression ratios of RAR and bz2 can be pretty similar when done this way.

            Comment

            • Yu-Xi Lim

              #7
              Re: Tarfile .bz2

              Martin v. Löwis wrote:
              Well, .jpg files are already compressed in a lossy way (.jpg is
              inherently lossy); to compress it further, you need to increase
              the loss. PNG is also compressed already, see
              Not really. Stuffit has a JPEG compressor which takes advantage of the
              fact that the JPEG algorithm isn't as optimal as it can be. It converts
              JPEG images to its own more compact representation which then can be
              converted back to JPEG as needed, without any loss. It is sadly not free.


              Comment

              • Fredrik Lundh

                #8
                Re: Tarfile .bz2

                Martin v. Löwis wrote:
                Well, .jpg files are already compressed in a lossy way (.jpg is
                inherently lossy); to compress it further, you need to increase
                the loss.
                or use a better algorithm, such as JPEG 2000 or Microsoft's HD Photo,
                which both give better visual quality at lower bit rates (which means
                that you can often get by with around half the bits compared to JPEG).

                </F>

                Comment

                • Piet van Oostrum

                  #9
                  Re: Tarfile .bz2

                  >>>>"Martin v. Löwis" <martin@v.loewi s.de(MvL) wrote:
                  >MvLJordan schrieb:
                  >>Not really on topic anymore but what's the method for tar.gz?
                  >MvLIt works like .tar.bz2, except that it uses gzip (www.gzip.org)
                  >MvLas the compression library. The underlying compression algorithm
                  >MvLis LZW.
                  No, it uses a compression algorithm based on LZ77 (called DEFLATE).
                  Therefore gzip was not encumbered by the the LZW patent.
                  --
                  Piet van Oostrum <piet@cs.uu.n l>
                  URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C 4]
                  Private email: piet@vanoostrum .org

                  Comment

                  Working...