Python's GzipFile class is read via BufferedReader

That's why I'm talking about what happened, but I noticed that I was writing code using GzipFile, so it's a memo.

What is GzipFile?

A class that handles gzip in Python.

You can read and write a local Gzip file by passing the file name to the constructor, and a "like" Gzip object by passing fileobj.

Where BufferedReader is used

In in the constructor of GzipFile, as shown in the figure below.

When reading a GzipFile, it goes through the BufferedReader (*).

gzip_class.png

When you want to change the size of the buffer

GzipFile uses the default (io.DEFAULT_BUFFER_SIZE) for the BufferedReader's buffer size.

Depending on the io to be read, you may want to buffer in larger units (*). However, it seems that the buffer size cannot be changed by the function of GzipFile, so let's pass BufferedReader to fileobj of GzipFile.

Recommended Posts

Python's GzipFile class is read via BufferedReader
Where is python's fluentd??
What is Python's __init__.py?