NativeOutput.hx 704 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package python.io;
  2. import haxe.io.Output;
  3. import python.lib.Builtin;
  4. import python.lib.io.IOBase;
  5. import python.lib.io.RawIOBase;
  6. class NativeOutput<T:IOBase> extends Output {
  7. var stream:T;
  8. public var canSeek(get_canSeek, null):Bool;
  9. public function new (stream:T) {
  10. this.stream = stream;
  11. if (!stream.writable()) throw "Read only stream";
  12. }
  13. override public function close():Void
  14. {
  15. stream.close();
  16. }
  17. private function get_canSeek():Bool
  18. {
  19. return stream.seekable();
  20. }
  21. override public function prepare(nbytes:Int):Void
  22. {
  23. stream.truncate(nbytes);
  24. }
  25. override public function flush():Void
  26. {
  27. stream.flush();
  28. }
  29. public function tell() : Int
  30. {
  31. return stream.tell();
  32. }
  33. }