diff --git a/edosl0util/split.py b/edosl0util/split.py index b39454b13756c671757a5dbfd6b65394096e46c4..00fdb1b4221b043ba875e254ded9a7d82b98c9fd 100644 --- a/edosl0util/split.py +++ b/edosl0util/split.py @@ -1,6 +1,5 @@ import os import io -import array from datetime import datetime from edosl0util.timecode import unixtime @@ -14,7 +13,7 @@ def split_stream(fobj, minutes): :param fobj: A file-like object :param minutes: integer number of minutes """ - buf = array.array('B') # buffer for a single data file until it is written + buf = bytearray() # buffer for a single data file until it is written cur_bucket = 0 # cur time bucket of size 'minutes' pkt_count = 0 @@ -30,17 +29,17 @@ def split_stream(fobj, minutes): if pkt_bucket > cur_bucket: offset = fobj.tell() - original_offset - yield cur_bucket, offset, pkt_count, buf.tostring() + yield cur_bucket, offset, pkt_count, buf pkt_count = 0 - buf = array.array('c') + buf = bytearray() cur_bucket = pkt_bucket # this is an append operation - buf.fromstring(pkt.data) + buf += pkt.bytes() pkt_count += 1 offset = fobj.tell() - original_offset - yield cur_bucket, offset, pkt_count, buf.tostring() + yield cur_bucket, offset, pkt_count, buf def _replace_pdsname_stamp(filename, stamp): @@ -85,7 +84,7 @@ def split_file(filepath, minutes, destdir): :raises RuntimeError: If a file exists with the same name of a bucket file. """ destdir = destdir or '.' - stream = split_stream(io.open(filepath), minutes) + stream = split_stream(io.open(filepath, 'rb'), minutes) for timestamp, offset, pkts, blob in stream: stamp = datetime.utcfromtimestamp(timestamp) dirname, filename = os.path.split(filepath)