From 34ce91364bbcfa6562cd5084e646fa4affa27a87 Mon Sep 17 00:00:00 2001
From: Bruce Flynn <brucef@ssec.wisc.edu>
Date: Fri, 9 Oct 2015 20:18:21 +0000
Subject: [PATCH] Sync split module with recent stream changes

---
 edosl0util/split.py | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/edosl0util/split.py b/edosl0util/split.py
index b39454b..00fdb1b 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)
-- 
GitLab