Преглед на файлове

Allow negative offsets to peek near the end of the file

master
JustAnotherArchivist преди 1 година
родител
ревизия
ccf4d678fb
променени са 1 файла, в които са добавени 9 реда и са изтрити 1 реда
  1. +9
    -1
      warc-peek

+ 9
- 1
warc-peek Целия файл

@@ -16,6 +16,7 @@
# not attempt decompression when `1F 8B` is found in the last 512 bytes of the window. You can increase `LENGTH` to compensate for this if necessary.

import argparse
import io
import logging
import zlib

@@ -35,7 +36,14 @@ def finditer(b, sub):

def find_offsets(warcfile, offset, length):
with open(warcfile, 'rb') as fp:
fp.seek(offset)
if offset >= 0:
fp.seek(offset)
else:
# Negative offset: go back from EOF and fix offset for correct output
fp.seek(0, io.SEEK_END)
size = fp.tell()
fp.seek(offset, io.SEEK_END)
offset = size + offset
buffer = fp.read(length)

logger.debug('Buffer length: {:d}'.format(len(buffer)))


Зареждане…
Отказ
Запис