1
from itertools import chain
3
from bzrlib.errors import BinaryFile
4
from bzrlib.iterablefile import IterableFile
5
from bzrlib.osutils import file_iterator
7
"""Produce a file iterator that is guaranteed to be text, without seeking.
8
BinaryFile is raised if the file contains a NUL in the first 1024 bytes.
10
first_chunk = input.read(1024)
11
if '\x00' in first_chunk:
13
return IterableFile(chain((first_chunk,), file_iterator(input)))
16
def check_text_lines(lines):
17
"""Raise BinaryFile if the supplied lines contain NULs.
18
Only the first 1024 characters are checked.
20
f = IterableFile(lines)
21
if '\x00' in f.read(1024):
24
def check_text_path(path):
25
"""Check whether the supplied path is a text, not binary file.
26
Raise BinaryFile if a NUL occurs in the first 1024 bytes.
28
text_file(open(path, 'rb'))