Skip to content
Snippets Groups Projects
Commit 34ce9136 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

Sync split module with recent stream changes

parent 05577839
No related branches found
No related tags found
No related merge requests found
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment