gzip with file descriptor

Dmitry B.

I need to be able to open a gzipped CSV file using a file descriptor. When I do the following (this is simplified code that still trigger the error):

file_path = r"E39O6KS6J8MIZW.00.0f6db4e5.gz"
fd = os.open(file_path, os.O_RDONLY, os.O_BINARY)
# ...
file_object = gzip.GzipFile(fileobj=io.FileIO(fd, mode='rb'))
reader = csv.reader(io.BufferedReader(file_object))
for row in reader:
    print row

I get a CRC check error:

Traceback (most recent call last):
  File "./log_processing_scripts/dev.py", line 40, in <module>
    post()
  File "./log_processing_scripts/dev.py", line 36, in post
    for row in reader:
  File "C:\Python27\lib\gzip.py", line 252, in read
    self._read(readsize)
  File "C:\Python27\lib\gzip.py", line 299, in _read
    self._read_eof()
  File "C:\Python27\lib\gzip.py", line 338, in _read_eof
    hex(self.crc)))
IOError: CRC check failed 0x4b77635f != 0xbe13716L

The file is not(!) corrupted, I can process it just file with gzip.open(file_path).

What am I missing?

Robᵩ

The O_RDONLY and O_BINARY flags should be or'd together, like so:

fd = os.open(file_path, os.O_RDONLY | os.O_BINARY)

Reference: https://docs.python.org/2/library/os.html#open-constants

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Echo to file descriptor overwrites the file?

分類Dev

Using file descriptor with here document

分類Dev

Is it legal to read a file descriptor into NULL?

分類Dev

.gz (gzip) file analysis

分類Dev

Gzip file in Azure DevOps

分類Dev

GZIP File corrupted - but why?

分類Dev

write the integer value of a file descriptor to a file

分類Dev

Create a gzip file of a predetermined size

分類Dev

Pipe stdout to another process's file descriptor

分類Dev

Check number of available buffer characters in file descriptor

分類Dev

print: "IOError: [Errno 9] Bad file descriptor"

分類Dev

Reading fully from file descriptor of unknown size

分類Dev

File descriptor to read kernel log messages?

分類Dev

how to set file descriptor non-blocking?

分類Dev

redirect stdin from file descriptor in linux c

分類Dev

Read / write to the same file descriptor with shell redirection

分類Dev

Get file descriptor from file pointer without fileno()

分類Dev

How to limit Winston to only 1 file descriptor per log file

分類Dev

Opening a gzip file in python Apache Beam

分類Dev

gzip on a folder without changing the file extension

分類Dev

Django - HTTPStream of gzip file creaed on the fly

分類Dev

Can I decompress a .gzip file with tar?

分類Dev

compress file using /bin/gzip with particular patterns

分類Dev

accept(...) seems to be modifying the file descriptor parameter I give it

分類Dev

How to make stdin file descriptor ready when pressing a key?

分類Dev

How do I write to a specific raw file descriptor from Rust?

分類Dev

Duplicating file descriptor and seeking through both of them independently

分類Dev

Windows puma unable to load application due to backports Bad File descriptor

分類Dev

Syntax error: word unexpected on io redirection on file descriptor ≥10

Related 関連記事

  1. 1

    Echo to file descriptor overwrites the file?

  2. 2

    Using file descriptor with here document

  3. 3

    Is it legal to read a file descriptor into NULL?

  4. 4

    .gz (gzip) file analysis

  5. 5

    Gzip file in Azure DevOps

  6. 6

    GZIP File corrupted - but why?

  7. 7

    write the integer value of a file descriptor to a file

  8. 8

    Create a gzip file of a predetermined size

  9. 9

    Pipe stdout to another process's file descriptor

  10. 10

    Check number of available buffer characters in file descriptor

  11. 11

    print: "IOError: [Errno 9] Bad file descriptor"

  12. 12

    Reading fully from file descriptor of unknown size

  13. 13

    File descriptor to read kernel log messages?

  14. 14

    how to set file descriptor non-blocking?

  15. 15

    redirect stdin from file descriptor in linux c

  16. 16

    Read / write to the same file descriptor with shell redirection

  17. 17

    Get file descriptor from file pointer without fileno()

  18. 18

    How to limit Winston to only 1 file descriptor per log file

  19. 19

    Opening a gzip file in python Apache Beam

  20. 20

    gzip on a folder without changing the file extension

  21. 21

    Django - HTTPStream of gzip file creaed on the fly

  22. 22

    Can I decompress a .gzip file with tar?

  23. 23

    compress file using /bin/gzip with particular patterns

  24. 24

    accept(...) seems to be modifying the file descriptor parameter I give it

  25. 25

    How to make stdin file descriptor ready when pressing a key?

  26. 26

    How do I write to a specific raw file descriptor from Rust?

  27. 27

    Duplicating file descriptor and seeking through both of them independently

  28. 28

    Windows puma unable to load application due to backports Bad File descriptor

  29. 29

    Syntax error: word unexpected on io redirection on file descriptor ≥10

ホットタグ

アーカイブ