map2loop.mapdata.GzipFile#

class map2loop.mapdata.GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None)#

Bases: BaseStream

The GzipFile class simulates most of the methods of a file object with the exception of the truncate() method.

This class only supports opening files in binary mode. If you need to open a compressed file in text mode, use the gzip.open() function.

Constructor for the GzipFile class.

At least one of fileobj and filename must be given a non-trivial value.

The new class instance is based on fileobj, which can be a regular file, an io.BytesIO object, or any other object which simulates a file. It defaults to None, in which case filename is opened to provide a file object.

When fileobj is not None, the filename argument is only used to be included in the gzip file header, which may include the original filename of the uncompressed file. It defaults to the filename of fileobj, if discernible; otherwise, it defaults to the empty string, and in this case the original filename is not included in the header.

The mode argument can be any of ‘r’, ‘rb’, ‘a’, ‘ab’, ‘w’, ‘wb’, ‘x’, or ‘xb’ depending on whether the file will be read or written. The default is the mode of fileobj if discernible; otherwise, the default is ‘rb’. A mode of ‘r’ is equivalent to one of ‘rb’, and similarly for ‘w’ and ‘wb’, ‘a’ and ‘ab’, and ‘x’ and ‘xb’.

The compresslevel argument is an integer from 0 to 9 controlling the level of compression; 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression. 0 is no compression at all. The default is 9.

The mtime argument is an optional numeric timestamp to be written to the last modification time field in the stream when compressing. If omitted or None, the current time is used.

__init__(filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None)#

Constructor for the GzipFile class.

At least one of fileobj and filename must be given a non-trivial value.

The new class instance is based on fileobj, which can be a regular file, an io.BytesIO object, or any other object which simulates a file. It defaults to None, in which case filename is opened to provide a file object.

When fileobj is not None, the filename argument is only used to be included in the gzip file header, which may include the original filename of the uncompressed file. It defaults to the filename of fileobj, if discernible; otherwise, it defaults to the empty string, and in this case the original filename is not included in the header.

The mode argument can be any of ‘r’, ‘rb’, ‘a’, ‘ab’, ‘w’, ‘wb’, ‘x’, or ‘xb’ depending on whether the file will be read or written. The default is the mode of fileobj if discernible; otherwise, the default is ‘rb’. A mode of ‘r’ is equivalent to one of ‘rb’, and similarly for ‘w’ and ‘wb’, ‘a’ and ‘ab’, and ‘x’ and ‘xb’.

The compresslevel argument is an integer from 0 to 9 controlling the level of compression; 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression. 0 is no compression at all. The default is 9.

The mtime argument is an optional numeric timestamp to be written to the last modification time field in the stream when compressing. If omitted or None, the current time is used.

Methods

__init__([filename, mode, compresslevel, ...])

Constructor for the GzipFile class.

close()

Flush and close the IO object.

detach()

Disconnect this buffer from its underlying raw stream and return it.

fileno()

Invoke the underlying file object's fileno() method.

flush([zlib_mode])

Flush write buffers, if applicable.

isatty()

Return whether this is an 'interactive' stream.

peek(n)

read([size])

Read and return up to n bytes.

read1([size])

Implements BufferedIOBase.read1()

readable()

Return whether object was opened for reading.

readinto(buffer, /)

readinto1(buffer, /)

readline([size])

Read and return a line from the stream.

readlines([hint])

Return a list of lines from the stream.

rewind()

Return the uncompressed stream file position indicator to the beginning of the file

seek(offset[, whence])

Change the stream position to the given byte offset.

seekable()

Return whether object supports random access.

tell()

Return current stream position.

truncate([size])

Truncate file to size bytes.

writable()

Return whether object was opened for writing.

write(data)

Write buffer b to the IO stream.

writelines(lines, /)

Write a list of lines to stream.

Attributes

closed

mtime

Last modification time read from stream, or None

myfileobj

close()#

Flush and close the IO object.

This method has no effect if the file is already closed.

detach()#

Disconnect this buffer from its underlying raw stream and return it.

After the raw stream has been detached, the buffer is in an unusable state.

fileno()#

Invoke the underlying file object’s fileno() method.

This will raise AttributeError if the underlying file object doesn’t support fileno().

flush(zlib_mode=2)#

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

isatty()#

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mtime#

Last modification time read from stream, or None

read(size=-1)#

Read and return up to n bytes.

If the size argument is omitted, None, or negative, read and return all data until EOF.

If the size argument is positive, and the underlying raw stream is not ‘interactive’, multiple raw reads may be issued to satisfy the byte count (unless EOF is reached first). However, for interactive raw streams (as well as sockets and pipes), at most one raw read will be issued, and a short result does not imply that EOF is imminent.

Return an empty bytes object on EOF.

Return None if the underlying raw stream was open in non-blocking mode and no data is available at the moment.

read1(size=-1)#

Implements BufferedIOBase.read1()

Reads up to a buffer’s worth of data if size is negative.

readable()#

Return whether object was opened for reading.

If False, read() will raise OSError.

readline(size=-1)#

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)#

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

rewind()#

Return the uncompressed stream file position indicator to the beginning of the file

seek(offset, whence=0)#

Change the stream position to the given byte offset.

offset

The stream position, relative to ‘whence’.

whence

The relative position to seek from.

The offset is interpreted relative to the position indicated by whence. Values for whence are:

  • os.SEEK_SET or 0 – start of stream (the default); offset should be zero or positive

  • os.SEEK_CUR or 1 – current stream position; offset may be negative

  • os.SEEK_END or 2 – end of stream; offset is usually negative

Return the new absolute position.

seekable()#

Return whether object supports random access.

If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().

tell()#

Return current stream position.

truncate(size=None, /)#

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Return the new size.

writable()#

Return whether object was opened for writing.

If False, write() will raise OSError.

write(data)#

Write buffer b to the IO stream.

Return the number of bytes written, which is always the length of b in bytes.

Raise BlockingIOError if the buffer is full and the underlying raw stream cannot accept more data at the moment.

writelines(lines, /)#

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.