Browse Source

refactor: LuaFileMode and ILuaIOStream

Akeit0 6 months ago
parent
commit
a76a768f64

+ 5 - 58
src/Lua/IO/BinaryLuaIOStream.cs → src/Lua/IO/BinaryLuaStream.cs

@@ -2,35 +2,25 @@ using System.Text;
 
 namespace Lua.IO;
 
-internal sealed class BinaryLuaIOStream(LuaFileOpenMode mode, Stream innerStream) : ILuaIOStream
+internal sealed class BinaryLuaStream(LuaFileMode mode, Stream innerStream) : ILuaStream
 {
     ulong flushSize = ulong.MaxValue;
     ulong nextFlushSize = ulong.MaxValue;
 
-    public LuaFileOpenMode Mode => mode;
-    public LuaFileContentType ContentType => LuaFileContentType.Binary;
-
-    public ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken)
-    {
-        throw new InvalidOperationException("Cannot read lines from a binary stream. Open with text mode instead.");
-    }
+    public LuaFileMode Mode => mode;
 
     public ValueTask<LuaFileContent> ReadAllAsync(CancellationToken cancellationToken)
     {
-        ThrowIfNotReadable();
+        mode.ThrowIfNotReadable();
         using var memoryStream = new MemoryStream();
         innerStream.CopyTo(memoryStream);
         var bytes = memoryStream.ToArray();
         return new(new LuaFileContent(bytes));
     }
 
-    public ValueTask<string?> ReadStringAsync(int count, CancellationToken cancellationToken)
-    {
-        throw new InvalidOperationException("Cannot read lines string from a binary stream. Open with text mode instead.");
-    }
-
     public ValueTask WriteAsync(LuaFileContent content, CancellationToken cancellationToken)
     {
+        mode.ThrowIfNotReadable();
         if (content.Type != LuaFileContentType.Binary)
         {
             var encoding = Encoding.UTF8;
@@ -44,37 +34,10 @@ internal sealed class BinaryLuaIOStream(LuaFileOpenMode mode, Stream innerStream
         return WriteBytesAsync(content.ReadBytes().Span, cancellationToken);
     }
 
-    public ValueTask<byte[]?> ReadBytesAsync(int count, CancellationToken cancellationToken)
-    {
-        ThrowIfNotReadable();
-
-        if (count <= 0) return new((byte[]?)null);
-
-        var buffer = new byte[count];
-        var totalRead = 0;
-
-        while (totalRead < count)
-        {
-            var bytesRead = innerStream.Read(buffer, totalRead, count - totalRead);
-            if (bytesRead == 0) break; // End of stream
-            totalRead += bytesRead;
-        }
-
-        if (totalRead == 0) return new((byte[]?)null);
-        if (totalRead < count)
-        {
-            Array.Resize(ref buffer, totalRead);
-        }
-
-        return new(buffer);
-    }
-
 
     public ValueTask WriteBytesAsync(ReadOnlySpan<byte> buffer, CancellationToken cancellationToken)
     {
-        ThrowIfNotWritable();
-
-        if (mode is LuaFileOpenMode.Append or LuaFileOpenMode.ReadAppend)
+        if (mode.IsAppend())
         {
             innerStream.Seek(0, SeekOrigin.End);
         }
@@ -117,22 +80,6 @@ internal sealed class BinaryLuaIOStream(LuaFileOpenMode mode, Stream innerStream
         return innerStream.Seek(offset, origin);
     }
 
-    void ThrowIfNotReadable()
-    {
-        if (!innerStream.CanRead)
-        {
-            throw new IOException("Stream is not readable.");
-        }
-    }
-
-    void ThrowIfNotWritable()
-    {
-        if (!innerStream.CanWrite)
-        {
-            throw new IOException("Stream is not writable.");
-        }
-    }
-
     public void Dispose()
     {
         if (innerStream.CanWrite) innerStream.Flush();

+ 9 - 9
src/Lua/IO/ConsoleStandardIO.cs

@@ -7,27 +7,27 @@ namespace Lua.IO;
 /// </summary>
 public sealed class ConsoleStandardIO : ILuaStandardIO
 {
-    ILuaIOStream? standardInput;
+    ILuaStream? standardInput;
 
-    public ILuaIOStream Input => standardInput ??=
-        new StandardIOStream(ILuaIOStream.CreateStreamWrapper(
+    public ILuaStream Input => standardInput ??=
+        new StandardIOStream(ILuaStream.CreateStreamWrapper(
             ConsoleHelper.OpenStandardInput(),
             LuaFileOpenMode.Read));
 
-    ILuaIOStream? standardOutput;
+    ILuaStream? standardOutput;
 
-    public ILuaIOStream Output
+    public ILuaStream Output
 
         => standardOutput ??=
-            new StandardIOStream(ILuaIOStream.CreateStreamWrapper(
+            new StandardIOStream(ILuaStream.CreateStreamWrapper(
                 ConsoleHelper.OpenStandardOutput(),
                 LuaFileOpenMode.Write));
 
 
-    ILuaIOStream? standardError;
+    ILuaStream? standardError;
 
-    public ILuaIOStream Error => standardError ??=
-        new StandardIOStream(ILuaIOStream.CreateStreamWrapper(
+    public ILuaStream Error => standardError ??=
+        new StandardIOStream(ILuaStream.CreateStreamWrapper(
             ConsoleHelper.OpenStandardError(),
             LuaFileOpenMode.Write));
 }

+ 12 - 11
src/Lua/IO/FileSystem.cs

@@ -31,12 +31,12 @@
         }
 
 
-        ILuaIOStream Open(string path, LuaFileOpenMode luaMode, LuaFileContentType contentType)
+        ILuaStream Open(string path, LuaFileOpenMode openMode, LuaFileContentType contentType)
         {
-            var (mode, access) = GetFileMode(luaMode);
+            var (mode, access) = GetFileMode(openMode);
             Stream stream;
 
-            if (luaMode == LuaFileOpenMode.ReadAppend)
+            if (openMode == LuaFileOpenMode.ReadAppend)
             {
                 stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete);
             }
@@ -45,11 +45,12 @@
                 stream = File.Open(path, mode, access, FileShare.ReadWrite | FileShare.Delete);
             }
 
-            ILuaIOStream wrapper = contentType == LuaFileContentType.Binary
-                ? new BinaryLuaIOStream(luaMode, stream)
-                : new TextLuaIOStream(luaMode, stream);
+            var fileMode = LuaFileModeExtensions.GetMode(openMode, contentType);
+            ILuaStream wrapper = contentType == LuaFileContentType.Binary
+                ? new BinaryLuaStream(fileMode, stream)
+                : new TextLuaStream(fileMode, stream);
 
-            if (luaMode == LuaFileOpenMode.ReadAppend)
+            if (openMode == LuaFileOpenMode.ReadAppend)
             {
                 wrapper.Seek(0, SeekOrigin.End);
             }
@@ -57,7 +58,7 @@
             return wrapper;
         }
 
-        public ILuaIOStream Open(string path, LuaFileMode mode)
+        public ILuaStream Open(string path, LuaFileMode mode)
         {
             if (mode is LuaFileMode.ReadBinaryOrText)
             {
@@ -69,7 +70,7 @@
             return Open(path, openMode, contentType);
         }
 
-        public ILuaIOStream Open(string path, string mode)
+        public ILuaStream Open(string path, string mode)
         {
             var flags = LuaFileModeExtensions.ParseModeString(mode);
             return Open(path, flags);
@@ -96,9 +97,9 @@
             return Path.GetTempFileName();
         }
 
-        public ILuaIOStream OpenTempFileStream()
+        public ILuaStream OpenTempFileStream()
         {
-            return new TextLuaIOStream(LuaFileOpenMode.ReadAppend, File.Open(Path.GetTempFileName(), FileMode.Open, FileAccess.ReadWrite));
+            return new TextLuaStream(LuaFileMode.ReadUpdateText, File.Open(Path.GetTempFileName(), FileMode.Open, FileAccess.ReadWrite));
         }
     }
 }

+ 2 - 2
src/Lua/IO/ILuaFileSystem.cs

@@ -3,10 +3,10 @@
 public interface ILuaFileSystem
 {
     public bool IsReadable(string path);
-    public ILuaIOStream Open(string path, LuaFileMode mode);
+    public ILuaStream Open(string path, LuaFileMode mode);
     public void Rename(string oldName, string newName);
     public void Remove(string path);
     public string DirectorySeparator { get; }
     public string GetTempFileName();
-    public ILuaIOStream OpenTempFileStream();
+    public ILuaStream OpenTempFileStream();
 }

+ 0 - 28
src/Lua/IO/ILuaIOStream.cs

@@ -1,28 +0,0 @@
-namespace Lua.IO
-{
-    public interface ILuaIOStream : IDisposable
-    {
-        public LuaFileOpenMode Mode { get; }
-
-        public LuaFileContentType ContentType { get; }
-        public ValueTask<LuaFileContent> ReadAllAsync(CancellationToken cancellationToken);
-        public ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken);
-        public ValueTask<string?> ReadStringAsync(int count, CancellationToken cancellationToken);
-        public ValueTask WriteAsync(LuaFileContent content, CancellationToken cancellationToken);
-        public ValueTask FlushAsync(CancellationToken cancellationToken);
-        public void SetVBuf(LuaFileBufferingMode mode, int size);
-        public long Seek(long offset, SeekOrigin origin);
-
-        public static ILuaIOStream CreateStreamWrapper(Stream stream, LuaFileOpenMode mode, LuaFileContentType contentType = LuaFileContentType.Text)
-        {
-            return contentType == LuaFileContentType.Binary
-                ? new BinaryLuaIOStream(mode, stream)
-                : new TextLuaIOStream(mode, stream);
-        }
-
-        public void Close()
-        {
-            Dispose();
-        }
-    }
-}

+ 3 - 3
src/Lua/IO/ILuaStandardIO.cs

@@ -8,15 +8,15 @@ public interface ILuaStandardIO
     /// <summary>
     /// Open standard input stream
     /// </summary>
-    ILuaIOStream Input { get; }
+    ILuaStream Input { get; }
 
     /// <summary>
     /// Open standard output stream
     /// </summary>
-    ILuaIOStream Output { get; }
+    ILuaStream Output { get; }
 
     /// <summary>
     /// Open standard error stream
     /// </summary>
-    ILuaIOStream Error { get; }
+    ILuaStream Error { get; }
 }

+ 79 - 0
src/Lua/IO/ILuaStream.cs

@@ -0,0 +1,79 @@
+namespace Lua.IO
+{
+    public interface ILuaStream : IDisposable
+    {
+        public LuaFileMode Mode { get; }
+
+        public ValueTask<LuaFileContent> ReadAllAsync(CancellationToken cancellationToken)
+        {
+            Mode.ThrowIfNotReadable();
+
+            // Default implementation using ReadStringAsync
+            throw new NotImplementedException($"ReadAllAsync must be implemented by {GetType().Name}");
+        }
+
+        public ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken)
+        {
+            Mode.ThrowIfNotReadable();
+
+            Mode.ThrowIfNotText();
+
+            // Default implementation using ReadStringAsync
+            throw new NotImplementedException($"ReadLineAsync must be implemented by {GetType().Name}");
+        }
+
+        public ValueTask<string?> ReadStringAsync(int count, CancellationToken cancellationToken)
+        {
+            Mode.ThrowIfNotReadable();
+
+            Mode.ThrowIfNotText();
+            // Default implementation using ReadAllAsync
+            throw new NotImplementedException($"ReadStringAsync must be implemented by {GetType().Name}");
+        }
+
+        public ValueTask WriteAsync(LuaFileContent content, CancellationToken cancellationToken)
+        {
+            Mode.ThrowIfNotWritable();
+            if (content.Type == LuaFileContentType.Binary)
+            {
+                Mode.ThrowIfNotBinary();
+            }
+            else
+            {
+                Mode.ThrowIfNotText();
+            }
+
+            throw new NotImplementedException($"WriteAsync must be implemented by {GetType().Name}");
+        }
+
+        public ValueTask FlushAsync(CancellationToken cancellationToken)
+        {
+            // Default implementation does nothing (no buffering)
+            return default;
+        }
+
+        public void SetVBuf(LuaFileBufferingMode mode, int size)
+        {
+            // Default implementation does nothing (no configurable buffering)
+        }
+
+        public long Seek(long offset, SeekOrigin origin)
+        {
+            throw new NotSupportedException($"Seek is not supported by {GetType().Name}");
+        }
+
+        public static ILuaStream CreateStreamWrapper(Stream stream, LuaFileOpenMode openMode, LuaFileContentType contentType = LuaFileContentType.Text)
+        {
+            var mode = LuaFileModeExtensions.GetMode(openMode, contentType);
+            return contentType == LuaFileContentType.Binary
+                ? new BinaryLuaStream(mode, stream)
+                : new TextLuaStream(mode, stream);
+        }
+
+
+        public void Close()
+        {
+            Dispose();
+        }
+    }
+}

+ 3 - 5
src/Lua/IO/LuaChunkStream.cs

@@ -4,7 +4,7 @@ using System.Text;
 
 namespace Lua.IO;
 
-public sealed class LuaChunkStream : ILuaIOStream
+public sealed class LuaChunkStream : ILuaStream
 {
     public LuaChunkStream(Stream stream)
     {
@@ -56,14 +56,12 @@ public sealed class LuaChunkStream : ILuaIOStream
         disposable = null;
     }
 
-    public LuaFileOpenMode Mode => LuaFileOpenMode.Read;
-    public LuaFileContentType ContentType =>  
-        bytes.Span.StartsWith(LuaCompiler.LuaByteCodeSignature) ? LuaFileContentType.Binary : LuaFileContentType.Text;
+    public LuaFileMode Mode => LuaFileMode.Read | (bytes.Span.StartsWith(LuaCompiler.LuaByteCodeSignature) ? LuaFileMode.Binary : LuaFileMode.Text);
 
     public ValueTask<LuaFileContent> ReadAllAsync(CancellationToken cancellationToken)
     {
         var span = bytes.Span;
-        if (ContentType == LuaFileContentType.Binary)
+        if ((Mode & LuaFileMode.Binary) != 0)
         {
             return new(new LuaFileContent(bytes));
         }

+ 81 - 0
src/Lua/IO/LuaFileMode.cs

@@ -42,6 +42,21 @@ public enum LuaFileMode
 
 public static class LuaFileModeExtensions
 {
+    public static LuaFileMode GetMode(LuaFileOpenMode openMode, LuaFileContentType type)
+    {
+        var isBinary = type == LuaFileContentType.Binary;
+        return openMode switch
+        {
+            LuaFileOpenMode.Read => isBinary ? LuaFileMode.ReadBinary : LuaFileMode.ReadText,
+            LuaFileOpenMode.Write => isBinary ? LuaFileMode.WriteBinary : LuaFileMode.WriteText,
+            LuaFileOpenMode.Append => isBinary ? LuaFileMode.AppendBinary : LuaFileMode.AppendText,
+            LuaFileOpenMode.ReadWriteOpen => isBinary ? LuaFileMode.ReadUpdateBinary : LuaFileMode.ReadUpdateText,
+            LuaFileOpenMode.ReadWriteCreate => isBinary ? LuaFileMode.WriteUpdateBinary : LuaFileMode.WriteUpdateText,
+            LuaFileOpenMode.ReadAppend => isBinary ? LuaFileMode.AppendUpdateBinary : LuaFileMode.AppendUpdateText,
+            _ => throw new ArgumentOutOfRangeException(nameof(openMode), openMode, "Invalid file open mode")
+        };
+    }
+
     public static LuaFileOpenMode GetOpenMode(this LuaFileMode mode)
     {
         var hasUpdate = (mode & LuaFileMode.Update) != 0;
@@ -111,4 +126,70 @@ public static class LuaFileModeExtensions
 
         return true;
     }
+
+    public static bool IsAppend(this LuaFileMode mode)
+    {
+        return (mode & LuaFileMode.Append) != 0;
+    }
+
+    public static bool CanRead(this LuaFileMode mode)
+    {
+        return (mode & LuaFileMode.Read) != 0;
+    }
+
+    public static bool CanWrite(this LuaFileMode mode)
+    {
+        return (mode & LuaFileMode.Write) != 0 || (mode & LuaFileMode.Append) != 0;
+    }
+
+    public static bool IsBinary(this LuaFileMode mode)
+    {
+        return (mode & LuaFileMode.Binary) != 0;
+    }
+
+    public static bool IsText(this LuaFileMode mode)
+    {
+        return (mode & LuaFileMode.Text) != 0;
+    }
+
+
+    public static void ThrowIfNotValid(this LuaFileMode mode)
+    {
+        if (!mode.IsValid())
+        {
+            throw new ArgumentException("Invalid file mode flags", nameof(mode));
+        }
+    }
+
+    public static void ThrowIfNotReadable(this LuaFileMode mode)
+    {
+        if (!mode.CanRead())
+        {
+            throw new InvalidOperationException("This operation is only valid for readable streams.");
+        }
+    }
+
+    public static void ThrowIfNotWritable(this LuaFileMode mode)
+    {
+        if (!mode.CanWrite())
+        {
+            throw new InvalidOperationException("This operation is only valid for writable streams.");
+        }
+    }
+
+    public static void ThrowIfNotText(this LuaFileMode mode)
+    {
+        if (!mode.IsText())
+        {
+            throw new InvalidOperationException("This operation is only valid for text streams.");
+        }
+    }
+
+    public static void ThrowIfNotBinary(this LuaFileMode mode)
+    {
+        if (!mode.IsBinary())
+        {
+            throw new InvalidOperationException("This operation is only valid for binary streams.");
+        }
+    }
 }

+ 4 - 8
src/Lua/IO/MemoryStreams.cs

@@ -1,6 +1,6 @@
 namespace Lua.IO;
 
-public sealed class ByteMemoryStream(ReadOnlyMemory<byte> bytes) : ILuaIOStream
+public sealed class ByteMemoryStream(ReadOnlyMemory<byte> bytes) : ILuaStream
 {
     private int position;
     private bool disposed;
@@ -11,9 +11,7 @@ public sealed class ByteMemoryStream(ReadOnlyMemory<byte> bytes) : ILuaIOStream
             throw new ArgumentNullException(nameof(bytes));
     }
 
-    public LuaFileOpenMode Mode => LuaFileOpenMode.Read;
-
-    public LuaFileContentType ContentType => LuaFileContentType.Binary;
+    public LuaFileMode Mode => LuaFileMode.ReadBinary;
 
     public void Dispose()
     {
@@ -87,14 +85,12 @@ public sealed class ByteMemoryStream(ReadOnlyMemory<byte> bytes) : ILuaIOStream
     }
 }
 
-public class CharMemoryStream(ReadOnlyMemory<char> contents) : ILuaIOStream
+public class CharMemoryStream(ReadOnlyMemory<char> contents) : ILuaStream
 {
     protected int Position;
     private bool disposed;
 
-    public LuaFileOpenMode Mode => LuaFileOpenMode.Read;
-
-    public LuaFileContentType ContentType => LuaFileContentType.Text;
+    public LuaFileMode Mode => LuaFileMode.ReadText;
 
     public void Dispose()
     {

+ 2 - 3
src/Lua/IO/StandardIOStream.cs

@@ -3,10 +3,9 @@
     /// <summary>
     /// Wrapper for standard IO streams that prevents closing
     /// </summary>
-    internal sealed class StandardIOStream(ILuaIOStream innerStream) : ILuaIOStream
+    internal sealed class StandardIOStream(ILuaStream innerStream) : ILuaStream
     {
-        public LuaFileOpenMode Mode => innerStream.Mode;
-        public LuaFileContentType ContentType => innerStream.ContentType;
+        public LuaFileMode Mode => innerStream.Mode;
 
         public ValueTask<LuaFileContent> ReadAllAsync(CancellationToken cancellationToken)
             => innerStream.ReadAllAsync(cancellationToken);

+ 7 - 29
src/Lua/IO/TextLuaIOStream.cs → src/Lua/IO/TextLuaStream.cs

@@ -3,25 +3,24 @@ using System.Text;
 
 namespace Lua.IO;
 
-internal sealed class TextLuaIOStream(LuaFileOpenMode mode, Stream innerStream) : ILuaIOStream
+internal sealed class TextLuaStream(LuaFileMode mode, Stream innerStream) : ILuaStream
 {
     Utf8Reader? reader;
     ulong flushSize = ulong.MaxValue;
     ulong nextFlushSize = ulong.MaxValue;
 
-    public LuaFileOpenMode Mode => mode;
-    public LuaFileContentType ContentType => LuaFileContentType.Text;
+    public LuaFileMode Mode => mode;
 
     public ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken)
     {
-        ThrowIfNotReadable();
+        mode.ThrowIfNotReadable();
         reader ??= new();
         return new(reader.ReadLine(innerStream));
     }
 
     public ValueTask<LuaFileContent> ReadAllAsync(CancellationToken cancellationToken)
     {
-        ThrowIfNotReadable();
+        mode.ThrowIfNotReadable();
         reader ??= new();
         var text = reader.ReadToEnd(innerStream);
         return new(new LuaFileContent(text));
@@ -29,25 +28,20 @@ internal sealed class TextLuaIOStream(LuaFileOpenMode mode, Stream innerStream)
 
     public ValueTask<string?> ReadStringAsync(int count, CancellationToken cancellationToken)
     {
-        ThrowIfNotReadable();
+        mode.ThrowIfNotReadable();
         reader ??= new();
         return new(reader.Read(innerStream, count));
     }
 
     public ValueTask WriteAsync(LuaFileContent content, CancellationToken cancellationToken)
     {
-        if (content.Type != LuaFileContentType.Text)
-        {
-            throw new InvalidOperationException("Cannot write binary content to a text stream. Use a binary stream instead.");
-        }
-
+        mode.ThrowIfNotWritable();
         return WriteAsync(content.ReadText(), cancellationToken);
     }
 
     public ValueTask WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken)
     {
-        ThrowIfNotWritable();
-        if (mode is LuaFileOpenMode.Append or LuaFileOpenMode.ReadAppend)
+        if (mode.IsAppend())
         {
             innerStream.Seek(0, SeekOrigin.End);
         }
@@ -106,22 +100,6 @@ internal sealed class TextLuaIOStream(LuaFileOpenMode mode, Stream innerStream)
         return innerStream.Seek(offset, origin);
     }
 
-    void ThrowIfNotReadable()
-    {
-        if (!innerStream.CanRead)
-        {
-            throw new IOException("Stream is not readable.");
-        }
-    }
-
-    void ThrowIfNotWritable()
-    {
-        if (!innerStream.CanWrite)
-        {
-            throw new IOException("Stream is not writable.");
-        }
-    }
-
     public void Dispose()
     {
         try

+ 3 - 3
src/Lua/Standard/FileHandle.cs

@@ -31,7 +31,7 @@ public class FileHandle : ILuaUserData
         }
     });
 
-    ILuaIOStream stream;
+    ILuaStream stream;
     bool isClosed;
 
     public bool IsClosed => Volatile.Read(ref isClosed);
@@ -46,9 +46,9 @@ public class FileHandle : ILuaUserData
         fileHandleMetatable[Metamethods.Index] = IndexMetamethod;
     }
 
-    public FileHandle(Stream stream, LuaFileOpenMode mode, LuaFileContentType type = LuaFileContentType.Text) : this(ILuaIOStream.CreateStreamWrapper(stream, mode, type)) { }
+    public FileHandle(Stream stream, LuaFileOpenMode mode, LuaFileContentType type = LuaFileContentType.Text) : this(ILuaStream.CreateStreamWrapper(stream, mode, type)) { }
 
-    public FileHandle(ILuaIOStream stream)
+    public FileHandle(ILuaStream stream)
     {
         this.stream = stream;
     }

+ 2 - 2
tests/Lua.Tests/AbstractFileTests.cs

@@ -9,7 +9,7 @@ public class AbstractFileTests
 {
     class ReadOnlyFileSystem(Dictionary<string, string> dictionary) : NotImplementedExceptionFileSystemBase
     {
-        public override ILuaIOStream Open(string path, LuaFileMode mode)
+        public override ILuaStream Open(string path, LuaFileMode mode)
         {
             if (!dictionary.TryGetValue(path, out var value))
             {
@@ -34,7 +34,7 @@ public class AbstractFileTests
             await state.DoStringAsync(
                 """
                 local lines = {}
-                for line in io.lines("test1.txt") do
+                for line in io.lines("test.txt") do
                   table.insert(lines, line)
                   print(line)
                 end

+ 2 - 2
tests/Lua.Tests/Helpers/NotImplementedExceptionFileSystemBase.cs

@@ -14,7 +14,7 @@ namespace Lua.Tests.Helpers
             throw new NotImplementedException();
         }
 
-        public virtual ILuaIOStream Open(string path, LuaFileMode mode)
+        public virtual ILuaStream Open(string path, LuaFileMode mode)
         {
             throw new NotImplementedException();
         }
@@ -36,7 +36,7 @@ namespace Lua.Tests.Helpers
             throw new NotImplementedException();
         }
 
-        public ILuaIOStream OpenTempFileStream()
+        public ILuaStream OpenTempFileStream()
         {
             throw new NotImplementedException();
         }

+ 2 - 2
tests/Lua.Tests/Helpers/NotSupportedStreamBase.cs

@@ -2,13 +2,13 @@
 
 namespace Lua.Tests.Helpers
 {
-    public class NotSupportedStreamBase : ILuaIOStream
+    public class NotSupportedStreamBase : ILuaStream
     {
         public virtual void Dispose()
         {
         }
 
-        public virtual LuaFileOpenMode Mode => throw IOThrowHelpers.GetNotSupportedException();
+        public virtual LuaFileMode Mode => throw IOThrowHelpers.GetNotSupportedException();
         public LuaFileContentType ContentType=> throw IOThrowHelpers.GetNotSupportedException();
 
         public virtual ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken)

+ 0 - 4
tests/Lua.Tests/IOTests.cs

@@ -89,14 +89,12 @@ public class IOTests : IDisposable
         // Write text
         using (var stream = fileSystem.Open(testFile, LuaFileMode.WriteText))
         {
-            Assert.That(stream.ContentType, Is.EqualTo(LuaFileContentType.Text));
             await stream.WriteAsync(new(testContent), CancellationToken.None);
         }
 
         // Read text
         using (var stream = fileSystem.Open(testFile, LuaFileMode.ReadText))
         {
-            Assert.That(stream.ContentType, Is.EqualTo(LuaFileContentType.Text));
             var content = await stream.ReadAllAsync(CancellationToken.None);
             Assert.That(content.Type, Is.EqualTo(LuaFileContentType.Text));
             Assert.That(content.ReadString(), Is.EqualTo(testContent));
@@ -112,14 +110,12 @@ public class IOTests : IDisposable
         // Write bytes
         using (var stream = fileSystem.Open(testFile, LuaFileMode.WriteBinary))
         {
-            Assert.That(stream.ContentType, Is.EqualTo(LuaFileContentType.Binary));
             await stream.WriteAsync(new(testBytes), CancellationToken.None);
         }
 
         // Read bytes
         using (var stream = fileSystem.Open(testFile, LuaFileMode.ReadBinary))
         {
-            Assert.That(stream.ContentType, Is.EqualTo(LuaFileContentType.Binary));
             var content = await stream.ReadAllAsync(CancellationToken.None);
             Assert.That(content.Type, Is.EqualTo(LuaFileContentType.Binary));
             Assert.That(content.ReadBytes().ToArray(), Is.EqualTo(testBytes));

+ 1 - 0
tests/Lua.Tests/LuaTests.cs

@@ -15,6 +15,7 @@ public class LuaTests
     //[TestCase("tests-lua/pm.lua")] //string.match is not implemented
     //[TestCase("tests-lua/sort.lua")] //check for "invalid order function" is not implemented
     //[TestCase("tests-lua/calls.lua")] //  string.dump and reader function for load chunk is not implemented
+    [TestCase("tests-lua/files.lua")]
     [TestCase("tests-lua/closure.lua")]
     [TestCase("tests-lua/errors.lua")] // get table name  if nil is not implemented
     [TestCase("tests-lua/events.lua")]