NativeOutput.hx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package cs.io;
  2. import haxe.Int64;
  3. import haxe.io.Bytes;
  4. import haxe.io.Output;
  5. class NativeOutput extends Output
  6. {
  7. var canSeek(get_canSeek, null):Bool;
  8. var stream:cs.system.io.Stream;
  9. public function new(stream)
  10. {
  11. this.stream = stream;
  12. if (!stream.CanWrite) throw "Read-only stream";
  13. }
  14. override public function writeByte(c:Int):Void
  15. {
  16. stream.WriteByte(c);
  17. }
  18. override public function close():Void
  19. {
  20. stream.Close();
  21. }
  22. override public function flush():Void
  23. {
  24. stream.Flush();
  25. }
  26. override public function prepare(nbytes:Int):Void
  27. {
  28. //TODO see if implementation is correct
  29. stream.SetLength(haxe.Int64.add(stream.Length, cast(nbytes, Int64)));
  30. }
  31. private function get_canSeek():Bool
  32. {
  33. return stream.CanSeek;
  34. }
  35. public function seek( p : Int, pos : sys.io.FileSeek ) : Void
  36. {
  37. var p = switch(pos)
  38. {
  39. case SeekBegin: cs.system.io.SeekOrigin.Begin;
  40. case SeekCur: cs.system.io.SeekOrigin.Current;
  41. case SeekEnd: cs.system.io.SeekOrigin.End;
  42. };
  43. stream.Seek(cast(p, Int64), p);
  44. }
  45. public function tell() : Int
  46. {
  47. return cast(stream.Position, Int);
  48. }
  49. }