#!/usr/bin/env python36
#=======================================================================================
# Read/write binary imnage file
#=======================================================================================
print("Content-Type: text/html \n")     #required http response header (w/ extra line)

input  = "/home/sultans/web/python/demo/file/folder.gif"
output = "/home/sultans/web/data/folder.gif" 

infileHdl   = open(input,  "rb")        #notice read binary option
outfileHdl  = open(output, "wb")        #notice read binary option

byteList = infileHdl.read( )            #read entire file into a list of bytes
outfileHdl.write(byteList)              #write entire file 

infileHdl.close( )                      #close file
outfileHdl.close( )                     #close file


print(byteList)                         # b'GIF89a\x14\x00\x16\x00\xc4/...'

for  byte  in  byteList :               #loop through the list
    print(byte," ",end="")              # 71 73 70 56 97 194 255 204 0 51 ...