Class CabEntry

Class CabEntry

Namespace: Aspose.Zip.Cab
Assembly: Aspose.Zip.dll (25.2.0)

Represents a single file within cab archive.

public sealed class CabEntry : IArchiveFileEntry

Inheritance

objectCabEntry

Implements

IArchiveFileEntry

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Properties

Length

Gets the length of the entry in bytes.

public uint Length { get; }

Property Value

uint

ModificationTime

Gets last modified date and time.

public DateTime ModificationTime { get; }

Property Value

DateTime

Name

Gets name of the entry within the archive.

public string Name { get; }

Property Value

string

Methods

Extract(string)

Extracts the entry to the filesystem by the path provided.

public FileInfo Extract(string path)

Parameters

path string

The path to destination file. If the file already exists, it will be overwritten.

Returns

FileInfo

The file info of a composed file.

Examples

using (var archive = new CabArchive("archive.cab"))
{
    archive.Entries[0].Extract("data.bin");
}

Exceptions

ArgumentNullException

path is null.

SecurityException

The caller does not have the required permission to access.

ArgumentException

The path is empty, contains only white spaces, or contains invalid characters.

UnauthorizedAccessException

Access to file path is denied.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

NotSupportedException

File at path contains a colon (:) in the middle of the string.

FileNotFoundException

The file is not found.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

IOException

The file is already open.

NotSupportedException

Stream initialization failed due to wrong data.

InvalidDataException

The archive is corrupted.

Extract(Stream)

Extracts the entry to the stream provided.

public void Extract(Stream destination)

Parameters

destination Stream

Destination stream. Must be writable.

Examples

Extract an entry of cab archive.

Using (var archive = new CabArchive("archive.cab"))
{
    archive.Entries[0].Extract(httpResponseStream);
}

Exceptions

ArgumentException

destination does not support writing.

NotSupportedException

Stream initialization failed due to wrong data.

InvalidDataException

Archive is corrupted.

Open()

Opens the entry for extraction and provides a stream with entry content.

public Stream Open()

Returns

Stream

The stream that represents the contents of the entry.

Examples

Usage: Stream decompressed = entry.Open();

.NET 4.0 and higher - use Stream.CopyTo method: decompressed.CopyTo(httpResponse.OutputStream)

.NET 3.5 and before - copy bytes manually:

byte[] buffer = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(buffer, 0, buffer.Length)))
 fileStream.Write(buffer, 0, bytesRead);
```</p>

#### Remarks

Read from the stream to get the original content of a file. See examples section.

#### Exceptions

 [NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception)

Stream initialization failed due to wrong data.

 [InvalidDataException](https://learn.microsoft.com/dotnet/api/system.io.invaliddataexception)

The archive is corrupted.

### <a id="Aspose_Zip_Cab_CabEntry_ToString"></a> ToString\(\)

```csharp
public override string ToString()

Returns

string

 English