Docker python client API copy
Question: I am using Docker python client API 'copy'. Response from copy is of type
`requests.packages.urllib3.HTTPResponse`

Does it need to be handled differently for different types of file?

I copied a text file from container but when I try to read it using
`response.read()` I am getting text data mixed with binary data. I see content
decoders as

    
    
    >>>resonse.CONTENT_DECODERS
    >>>['gzip', 'deflate']
    

What is the best way to handle/read/dump the response from copy API ?


Answer: The response from the docker API is an uncompressed tar file. I had to read
docker's source code to know the format of the response, as this is not
documented. For instance, to download a file at `remote_path`, you need to do
the following:

    
    
    import tarfile, StringIO, os
    reply = docker.copy(container, remote_path)
    filelike = StringIO.StringIO(reply.read())
    tar = tarfile.open(fileobj = filelike)
    file = tar.extractfile(os.path.basename(remote_path))
    print file.read()
    

The code should be modified to work on folders.

