Commit f80fadab authored by W. Trevor King's avatar W. Trevor King
Browse files

Move need_to_reorder_bytes from binarywave to util.

We'll be needing it for packed.load, so it's not binarywave-specific.
parent ead1da8a
......@@ -36,6 +36,7 @@ from .struct import Structure as _Structure
from .struct import Field as _Field
from .util import assert_null as _assert_null
from .util import byte_order as _byte_order
from .util import need_to_reorder_bytes as _need_to_reorder_bytes
from .util import checksum as _checksum
......@@ -226,15 +227,6 @@ WaveHeader5 = _Structure(
# End IGOR constants and typedefs from IgorBin.h
# Begin functions from ReadWave.c
def _need_to_reorder_bytes(version):
# If the low order byte of the version field of the BinHeader
# structure is zero then the file is from a platform that uses
# different byte-ordering and therefore all data will need to be
# reordered.
return version & 0xFF == 0
def _version_structs(version, byte_order):
if version == 1:
bin = BinHeader1
......@@ -271,7 +263,7 @@ def load(filename, strict=True):
version = BinHeaderCommon.unpack_dict_from(b)['version']
needToReorderBytes = _need_to_reorder_bytes(version)
byteOrder = _byte_order(needToReorderBytes)
if needToReorderBytes:
BinHeaderCommon.set_byte_order(byteOrder)
version = BinHeaderCommon.unpack_dict_from(b)['version']
......
......@@ -63,6 +63,14 @@ def byte_order(needToReorderBytes):
return '<' # little-endian
return '>' # big-endian
# From ReadWave.c
def need_to_reorder_bytes(version):
# If the low order byte of the version field of the BinHeader
# structure is zero then the file is from a platform that uses
# different byte-ordering and therefore all data will need to be
# reordered.
return version & 0xFF == 0
# From ReadWave.c
def checksum(buffer, byte_order, oldcksum, numbytes):
x = _numpy.ndarray(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment