// Copyright (C) 2024, The Duplicati Team // https://duplicati.com, hello@duplicati.com // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.Collections.Generic; namespace Duplicati.Library.Interface { /// /// Enumerates the possible modes for compression and decompression /// public enum ArchiveMode { /// /// Indicates compression i.e. write archive mode, which means that the stream must be writeable /// Write, /// /// Indicates decompression i.e. read archive mode, which means that the stream must be readable /// Read } /// /// A value that is given to the compressor as a hint /// to how compressible the file is /// public enum CompressionHint { /// /// Indicates that the compression module should decide /// Default, /// /// Indicates that the file is compressible /// Compressible, /// /// Indicates that the files is incompressible /// Noncompressible } /// /// An interface for passing additional hints to the compressor /// about the expected contents of the volume /// public interface ICompressionHinting : ICompression { /// /// Gets or sets a value indicating whether this /// instance is in low overhead mode. /// /// true if low overhead mode; otherwise, false. bool LowOverheadMode { get; set; } } public interface IArchiveReader { /// /// Returns all files in the archive, matching the prefix, if any. /// /// An optional prefix for limiting the files returned /// All files in the archive, matching the prefix, if any string[] ListFiles(string prefix); /// /// Returns all files in the archive, matching the prefix, if any. /// /// An optional prefix for limiting the files returned /// All files in the archive, matching the prefix, if any IEnumerable> ListFilesWithSize(string prefix); /// /// Returns a stream with data from the given file in archive. /// /// The file to read the data from /// A stream with data from the given file /// This method has slightly strange logic, in that it will return a null value if the file does not exist, instead of throwing an exception System.IO.Stream OpenRead(string file); /// /// Returns the last modification time for the file /// /// The name of the file to examine /// The timestamp on the file DateTime GetLastWriteTime(string file); /// /// Returns a value indicating if the specified file exists /// /// The name of the file to examine /// True if the file exists, false otherwise bool FileExists(string file); } public interface IArchiveWriter { /// /// Creates a file in the archive. /// /// The file to create in the archive /// A hint to the compressor as to how compressible the file data is /// The time the file was last written /// A stream with the data to write into the file System.IO.Stream CreateFile(string file, CompressionHint hint, DateTime lastWrite); /// /// The size in bytes of the buffer that will be written when flushed /// long FlushBufferSize { get; } } /// /// An interface for accessing files in an archive, such as a folder or compressed file. /// All modules that implements compression must implement this interface. /// The classes that implements this interface MUST also /// implement a default constructor and a constructor that /// has the signature new(string file, Dictionary<string, string> options). /// The default constructor is used to construct an instance /// so the DisplayName and other values can be read. /// The other constructor is used to do the actual work. /// The input file may not exist or have zero length, in which case it should be created. /// public interface ICompression : IDynamicModule, IDisposable, IArchiveReader, IArchiveWriter { /// /// The total size of the archive. /// long Size { get; } /// /// The extension that the compression implementation adds to the filename /// string FilenameExtension { get; } /// /// A localized string describing the compression module with a friendly name /// string DisplayName { get; } /// /// A localized description of the compression module /// string Description { get; } } }