From d580412b08047dc4fd8bec903eb1bd3d36d6ee9e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 19 Dec 2022 00:38:24 +0000 Subject: [PATCH] Add Seek method to IReadOnlyFilesystem. --- Interfaces/IReadOnlyFilesystem.cs | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Interfaces/IReadOnlyFilesystem.cs b/Interfaces/IReadOnlyFilesystem.cs index b16c447d7..1189aba28 100644 --- a/Interfaces/IReadOnlyFilesystem.cs +++ b/Interfaces/IReadOnlyFilesystem.cs @@ -39,10 +39,13 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text; using Aaru.CommonTypes.AaruMetadata; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Structs; +using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes; +using FileSystemInfo = Aaru.CommonTypes.Structs.FileSystemInfo; namespace Aaru.CommonTypes.Interfaces; @@ -136,6 +139,34 @@ public interface IReadOnlyFilesystem : IFilesystem /// The file node. /// Error number. ErrorNumber CloseFile(IFileNode node); + + /// Move the file node position pointer to the specified position with the specified origin + /// The file node. + /// Desired position. + /// From where in the file to move the position pointer to. + /// Error number. + ErrorNumber Seek(IFileNode node, long position, SeekOrigin origin) + { + if(node is null) + return ErrorNumber.InvalidArgument; + + long desiredPosition = origin switch + { + SeekOrigin.Begin => position, + SeekOrigin.End => node.Length + position, + _ => node.Offset + position + }; + + if(desiredPosition < 0) + return ErrorNumber.InvalidArgument; + + if(desiredPosition >= node.Length) + return ErrorNumber.InvalidArgument; + + node.Offset = desiredPosition; + + return ErrorNumber.NoError; + } } /// Represents an opened file from a filesystem @@ -146,5 +177,5 @@ public interface IFileNode /// File length long Length { get; } /// Current position in file - long Offset { get; } + long Offset { get; set; } } \ No newline at end of file