NativeBytesInput.hx 739 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package python.io;
  2. import haxe.io.Eof;
  3. import haxe.io.Input;
  4. import python.io.IInput;
  5. import python.io.IoTools;
  6. import python.lib.Builtin;
  7. import python.lib.Bytearray;
  8. import python.lib.io.RawIOBase;
  9. import python.lib.io.IOBase.SeekSet;
  10. class NativeBytesInput extends NativeInput<RawIOBase> implements IInput {
  11. public function new (stream:RawIOBase) {
  12. super(stream);
  13. }
  14. override public function readByte():Int
  15. {
  16. var ret = stream.read(1);
  17. if (ret.length == 0) throwEof();
  18. return ret.get(0);
  19. }
  20. public function seek( p : Int, pos : sys.io.FileSeek ) : Void
  21. {
  22. wasEof = false;
  23. return IoTools.seekInBinaryMode(stream, p, pos);
  24. }
  25. override function readinto (b:Bytearray):Int {
  26. return stream.readinto(b);
  27. }
  28. }