Skip to content

Commit

Permalink
add more documentation to mention io.BytesIO objects
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbelden committed Feb 17, 2020
1 parent 7df1334 commit 4354461
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions fastavro/_read_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,18 @@ class reader(file_reader):
for record in avro_reader:
process_record(record)
The `fo` argument is a file-like object so another common example usage
would use an `io.BytesIO` object like so::
from io import BytesIO
from fastavro import writer, reader
fo = BytesIO()
writer(fo, schema, records)
fo.seek(0)
for record in reader(fo):
process_record(record)
.. attribute:: metadata
Key-value pairs in the header metadata
Expand Down
9 changes: 9 additions & 0 deletions fastavro/_write_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ def writer(fo,
with open('weather.avro', 'wb') as out:
writer(out, parsed_schema, records)
The `fo` argument is a file-like object so another common example usage
would use an `io.BytesIO` object like so::
from io import BytesIO
from fastavro import writer
fo = BytesIO()
writer(fo, schema, records)
Given an existing avro file, it's possible to append to it by re-opening
the file in `a+b` mode. If the file is only opened in `ab` mode, we aren't
able to read some of the existing header information and an error will be
Expand Down

0 comments on commit 4354461

Please sign in to comment.