Ejemplo n.º 1
0
def decompressFileDefault(name, overwrite=False, outname=None):
    """
    :type string: name      - name of file to decompress
    :type bool:   overwrite - overwrite destination
    :type string: outname   - name for decompressed file, not required.
                              Default will be '.'.join([name, 'lz4'])
    Generic decompress method for a file. Removes .lz4 to original file name
    for output, unless outname is provided.

    ***WARNING*** Currently uses lz4f.compressFrame, which will read the entire
    original file into memory, then pass to c-module for compression. Avoid
    using this for large files until migrated to advCompress functions.
    """
    if not outname:
        print 'testing'
        outname = name.replace('.lz4', '')
        if outname == name:
            print(''.join([
                'File does not contain .lz4 extension. ',
                'Please provide outname.'
            ]))
            return
        if os.path.exists(outname) and not overwrite:
            print(''.join([
                'Output file exists! Please authorize overwrite or',
                ' specify a different outfile name.'
            ]))
    infile = Lz4File.open(name)
    infile.decompress(outname)
Ejemplo n.º 2
0
 def lz4open(cls, name=None, mode='r', fileobj=None):
     if name and not fileobj:
         fileobj=__builtin__.open(name, 'rb')
     elif not name and not fileobj:
         print('Unable to open without a name or fileobj')
         return
     if not name and hasattr(fileobj.name):
         name = fileobj.name
     lz4FileOut = Lz4File.open(fileObj=fileobj)
     try:
         t = cls(None, mode, lz4FileOut)
     except:
         lz4FileOut.close()
     t._extfileobj = False
     return t
Ejemplo n.º 3
0
 def lz4open(cls, name, mode='r', fileobj=None, **kwargs):
     try:
         import lz4tools
         Lz4File = lz4tools.Lz4File
     except (ImportError, AttributeError):
         raise CompressionError("Lz4file module is not available")
     if name and fileobj is None:
         try:
             fileobj = Lz4File.open(name)
         except IOError:
             raise ReadError('Not a lz4 file')
     elif not name and not fileobj:
         print('Unable to open without a name or fileobj')
         return
     if not name and hasattr(fileobj, 'name'):
         name = fileobj.name
     try:
         t = cls(None, mode, fileobj)
     except:
         fileobj.close()
     t._extfileobj = False
     return t
Ejemplo n.º 4
0
 def lz4open(cls, name, mode='r', fileobj=None, **kwargs):
     try:
         import lz4tools
         Lz4File = lz4tools.Lz4File
     except (ImportError, AttributeError):
         raise CompressionError("Lz4file module is not available")
     if name and fileobj is None:
         try:
             fileobj = Lz4File.open(name)
         except IOError:
             raise ReadError('Not a lz4 file')
     elif not name and not fileobj:
         print('Unable to open without a name or fileobj')
         return
     if not name and hasattr(fileobj, 'name'):
         name = fileobj.name
     try:
         t = cls(None, mode, fileobj)
     except:
         fileobj.close()
     t._extfileobj = False
     return t
Ejemplo n.º 5
0
def decompressFileDefault(name, overwrite=False, outname=None):
    """
    :type string: name      - name of file to decompress
    :type bool:   overwrite - overwrite destination
    :type string: outname   - name for decompressed file, not required.
                              Default will be '.'.join([name, 'lz4'])
    Generic decompress method for a file. Removes .lz4 to original file name
    for output, unless outname is provided.

    ***WARNING*** Currently uses lz4f.compressFrame, which will read the entire
    original file into memory, then pass to c-module for compression. Avoid
    using this for large files until migrated to advCompress functions.
    """
    if not outname:
        outname = name.replace('.lz4', '')
        if outname == name:
            print(''.join(['File does not contain .lz4 extension. ',
                           'Please provide outname.']))
            return
        if os.path.exists(outname) and not overwrite:
            print(''.join(['Output file exists! Please authorize overwrite or',
                           ' specify a different outfile name.']))
    infile = Lz4File.open(name)
    infile.decompress(outname)
Ejemplo n.º 6
0
def open(name=None, fileObj=None):
    """  Alias for Lz4File.open()    """
    return Lz4File.open(name, fileObj)
Ejemplo n.º 7
0
def open(name=None, fileObj=None):
    """  Alias for Lz4File.open()    """
    return Lz4File.open(name, fileObj)