z/OS Tools & Language

Shrinking MVS files with ZipFile

  • 1.  Shrinking MVS files with ZipFile

    Posted 12-13-2017 11:18

    It is always good to see that the batteries included in Rocket Python actually work…

    Here is an example on how to compress a MVS file into a zip file:

    from zipfile import ZipFile
    
    zf = 'mm.zip'
    fn = '//MM.PRINTS'
    
    fz = fn.lstrip('/') # remove '/' from the MVS file name
    
    with open(fn, 'r') as fd:
        qstr = fd.read()
        with ZipFile(zf, 'w') as zd:
            # zd.write(fn,fz) <- does not work because internally called
            #                    os.stat() does not find z/OS dataset
            zd.writestr(fz, qstr)
            print zd.printdir()
    

    This runs in Python 2.7.13, File must fit into 64 bit memory.