NativeTextInput.hx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package python.io;
  2. import haxe.io.Eof;
  3. import haxe.io.Input;
  4. import python.io.IInput;
  5. import python.io.NativeInput;
  6. import python.lib.Builtin;
  7. import python.lib.io.RawIOBase;
  8. import python.lib.io.IOBase.SeekSet;
  9. import python.lib.io.TextIOBase;
  10. class NativeTextInput extends NativeInput<TextIOBase> implements IInput {
  11. public function new (stream:TextIOBase) {
  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.charCodeAt(0);
  19. }
  20. public function seek( p : Int, pos : sys.io.FileSeek ) : Void
  21. {
  22. wasEof = false;
  23. var pos = switch (pos) {
  24. case SeekBegin:
  25. SeekSet.SeekSet;
  26. case SeekCur:
  27. p = tell() + p;
  28. SeekSet.SeekSet;
  29. case SeekEnd :
  30. stream.seek(0, SeekSet.SeekEnd);
  31. p = tell() + p;
  32. SeekSet.SeekSet;
  33. }
  34. stream.seek(p, pos);
  35. }
  36. override public function readBytes(s:haxe.io.Bytes, pos:Int, len:Int):Int
  37. {
  38. throw "not implemented";
  39. /*
  40. if( pos < 0 || len < 0 || pos + len > s.length )
  41. throw haxe.io.Error.OutsideBounds;
  42. stream.seek(pos, python.lib.io.IOBase.SeekSet.SeekCur);
  43. var ba = Builtin.bytearray(len);
  44. var ret = stream.readinto(ba);
  45. s.blit(pos, haxe.io.Bytes.ofData(ba) ,0,len);
  46. if (ret == 0)
  47. throwEof();
  48. return ret;
  49. */
  50. }
  51. }