-#!/usr/bin/env python
+#!/usr/bin/env python3
# Copyright (C) 2013 Intra2net AG
#
'''
i = 0
pos = 0
- buf = ""
+ buf = b""
sep_len = len(separator)
if sep_len == 0:
raise Exception("empty separator")
if new_file_func is None:
- new_file_func = lambda prefix, i: open(prefix + str(i), 'w')
+ new_file_func = lambda prefix, i: open(prefix + str(i), 'wb')
output = new_file_func(prefix, i)
# buffered search. we try not to have the while input file in memory, as
# it's not needed
- with open(input_file, 'r') as f:
+ with open(input_file, 'rb') as f:
while True:
buf += f.read(BUFSIZE)
if len(buf) == 0:
# else: continue writing to the current output and iterate
output.write(buf)
- buf = ""
+ buf = b""
output.close()
def chunk_file(input_file, output_file, from_pos, to_pos):
- ifl = open(input_file, 'r')
- ofl = open(output_file, 'w')
+ ifl = open(input_file, 'rb')
+ ofl = open(output_file, 'wb')
ifl.seek(from_pos)
ofl.write(ifl.read(to_pos-from_pos))
chunk_file(input_file=args.input_file, output_file=args.output,
from_pos=args.from_pos, to_pos=args.to_pos)
else:
- split_file(separator=args.separator, prefix=args.prefix, input_file=args.input_file)
+ split_file(separator=args.separator.encode('UTF-8', errors="surrogateescape"),
+ prefix=args.prefix, input_file=args.input_file)