def initialize(input_file, out_stream, compressed): if compressed: bytestream = BytesIO(input_file.read()) input_file = GzipFile(None, "rb", fileobj=bytestream) gzip_stream = CompressedOutputStream(out_stream, "gzip") if compressed else None writer = gzip_stream if compressed else out_stream return input_file, writer