io_buffered_writer.py 551 B

123456789101112131415161718192021222324252627
  1. import uio as io
  2. try:
  3. io.BytesIO
  4. io.BufferedWriter
  5. except AttributeError:
  6. print('SKIP')
  7. raise SystemExit
  8. bts = io.BytesIO()
  9. buf = io.BufferedWriter(bts, 8)
  10. buf.write(b"foobar")
  11. print(bts.getvalue())
  12. buf.write(b"foobar")
  13. # CPython has different flushing policy, so value below is different
  14. print(bts.getvalue())
  15. buf.flush()
  16. print(bts.getvalue())
  17. buf.flush()
  18. print(bts.getvalue())
  19. # special case when alloc is a factor of total buffer length
  20. bts = io.BytesIO()
  21. buf = io.BufferedWriter(bts, 1)
  22. buf.write(b"foo")
  23. print(bts.getvalue())