ensure reader does not depend on tell API
MODIFY
fastavro/_read.pyx
fastavro/_read.pyx
@@ -594,9 +594,23 @@ except ImportError:
def _iter_avro_records(fo, header, codec, writer_schema, reader_schema):
- for block in _iter_avro_blocks(fo, header, codec, writer_schema, reader_schema):
- for record in block:
- yield record
+ cdef int32 i
+
+ sync_marker = header['sync']
+
+ read_block = BLOCK_READERS.get(codec)
+ if not read_block:
+ raise ValueError('Unrecognized codec: %r' % codec)
+
+ block_count = 0
+ while True:
+ block_count = read_long(fo)
+ block_fo = read_block(fo)
+
+ for i in range(block_count):
+ yield _read_data(block_fo, writer_schema, reader_schema)
+
+ skip_sync(fo, sync_marker)
def _iter_avro_blocks(fo, header, codec, writer_schema, reader_schema):

MODIFY
fastavro/_read_py.py
fastavro/_read_py.py
@@ -527,10 +527,25 @@ except ImportError:
def _iter_avro_records(fo, header, codec, writer_schema, reader_schema):
"""Return iterator over avro records."""
- for block in _iter_avro_blocks(fo, header, codec, writer_schema,
- reader_schema):
- for record in block:
- yield record
+ sync_marker = header['sync']
+
+ read_block = BLOCK_READERS.get(codec)
+ if not read_block:
+ raise ValueError('Unrecognized codec: %r' % codec)
+
+ block_count = 0
+ while True:
+ try:
+ block_count = read_long(fo)
+ except StopIteration:
+ return
+
+ block_fo = read_block(fo)
+
+ for i in xrange(block_count):
+ yield read_data(block_fo, writer_schema, reader_schema)
+
+ skip_sync(fo, sync_marker)
def _iter_avro_blocks(fo, header, codec, writer_schema, reader_schema):

MODIFY
tests/test_fastavro.py
tests/test_fastavro.py
@@ -47,7 +47,7 @@ def roundtrip(schema, records, pass_schema_to_reader=False):
class NoSeekMemoryIO(object):
"""Shim around MemoryIO which blocks access to everything but read.
- Used to ensure seek API isn't being depended on."""
+ Used to ensure seek and tell API isn't being depended on."""
def __init__(self, *args):
self.underlying = MemoryIO(*args)
@@ -56,7 +56,7 @@ class NoSeekMemoryIO(object):
return self.underlying.read(n)
def tell(self):
- return self.underlying.tell()
+ raise AssertionError("fastavro reader should not depend on tell")
def seek(self, *args):
raise AssertionError("fastavro reader should not depend on seek")

ensure reader does not depend on tell API