Re: 3.2 can't extract tarfile produced by 2.7

Discussion in 'Python' started by Ian Kelly, Dec 27, 2012.

  1. Ian Kelly

    Ian Kelly Guest

    On Thu, Dec 27, 2012 at 11:50 AM, Steven W. Orr <> wrote:
    > Really? I thought that the whole idea of using "rb" or "wb" was something
    > that was necessitated by WinBlo$e. We're not doing IO on a text file here.
    > It's a tar file which by definition is binary and it's not clear to me why
    > unicode has anything to do with it. The files you extract should be
    > unaffected and the archive you produce shouldn't care. Am I missing
    > something?


    Python 3 uses the 'b' mode to signify that a binary stream should be
    opened instead of a text stream. A binary stream returns bytes when
    read from. A text stream returns strings when read from, which means
    that the bytes must be decoded; it also performs optional newline
    conversion. For full details, see the io module documentation.

    You're correct that it makes no sense to open a tar file in binary
    mode, but the basic io.open constructor has no concept of file type
    and relies on the caller to specify the mode properly. The tarfile
    module has its own tarfile.open function which has no "text mode";
    this is generally the correct way to open a tar file. For some reason
    the OP is not using this but is instead opening the file with io.open
    (in the wrong mode) and then passing the already-opened file object to
    tarfile.open.
     
    Ian Kelly, Dec 27, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    1,057
  2. Faik Uygur

    umask option for tarfile extract

    Faik Uygur, Jun 15, 2006, in forum: Python
    Replies:
    0
    Views:
    392
    Faik Uygur
    Jun 15, 2006
  3. Antoon Pardon

    3.2 can't extract tarfile produced by 2.7

    Antoon Pardon, Dec 26, 2012, in forum: Python
    Replies:
    0
    Views:
    150
    Antoon Pardon
    Dec 26, 2012
  4. Steven W. Orr
    Replies:
    0
    Views:
    162
    Steven W. Orr
    Dec 27, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    110
    Ian Kelly
    Dec 27, 2012
Loading...

Share This Page