StandardIOStream.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. namespace Lua.IO
  2. {
  3. /// <summary>
  4. /// Wrapper for standard IO streams that prevents closing
  5. /// </summary>
  6. internal sealed class StandardIOStream(ILuaStream innerStream) : ILuaStream
  7. {
  8. public LuaFileOpenMode Mode => innerStream.Mode;
  9. public ValueTask<string> ReadAllAsync(CancellationToken cancellationToken)
  10. => innerStream.ReadAllAsync(cancellationToken);
  11. public ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken)
  12. => innerStream.ReadLineAsync(cancellationToken);
  13. public ValueTask<string?> ReadStringAsync(int count, CancellationToken cancellationToken)
  14. => innerStream.ReadStringAsync(count, cancellationToken);
  15. public ValueTask WriteAsync(ReadOnlyMemory<char> content, CancellationToken cancellationToken)
  16. => innerStream.WriteAsync(content, cancellationToken);
  17. public ValueTask FlushAsync(CancellationToken cancellationToken)
  18. => innerStream.FlushAsync(cancellationToken);
  19. public void SetVBuf(LuaFileBufferingMode mode, int size)
  20. => innerStream.SetVBuf(mode, size);
  21. public long Seek(long offset, SeekOrigin origin)
  22. => innerStream.Seek(offset, origin);
  23. public void Close()
  24. {
  25. throw new IOException("cannot close standard file");
  26. }
  27. public void Dispose()
  28. {
  29. // Do not dispose inner stream to prevent closing standard IO streams
  30. innerStream.Dispose();
  31. }
  32. }
  33. }