Class ArchiveEntry

Class ArchiveEntry

Namespace: Aspose.Zip
Assembly: Aspose.Zip.dll (25.1.0)

แสดงถึงไฟล์เดียวภายในคลังข้อมูล

public abstract class ArchiveEntry : IArchiveFileEntry

การสืบทอด

objectArchiveEntry

ที่สืบทอด

ArchiveEntryEncrypted, ArchiveEntryPlain

การใช้งาน

IArchiveFileEntry

สมาชิกที่สืบทอด

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

หมายเหตุ

แคสต์อินสแตนซ์ของ Aspose.Zip.ArchiveEntry เป็น Aspose.Zip.ArchiveEntryEncrypted เพื่อตรวจสอบว่าเอนทรีนั้นถูกเข้ารหัสหรือไม่

ตัวสร้าง

ArchiveEntry(string, CompressionSettings, Func<stream>, FileAttributes)

เริ่มต้นอินสแตนซ์ใหม่ของคลาส Aspose.Zip.ArchiveEntry

protected ArchiveEntry(string name, CompressionSettings compressionSettings, Func<stream> sourceProvider, FileAttributes fileAttributes)

พารามิเตอร์

name string

ชื่อเอนทรี

compressionSettings CompressionSettings

การตั้งค่าสำหรับการบีบอัดหรือการคลายบีบอัด

sourceProvider Func<Stream&gt;

วิธีการคืนค่า stream ที่มีข้อมูลเอนทรีที่ต้องบีบอัด

fileAttributes FileAttributes

คุณสมบัติจากระบบไฟล์

ArchiveEntry(string, CompressionSettings, Stream, FileAttributes, FileSystemInfo)

เริ่มต้นอินสแตนซ์ใหม่ของคลาส Aspose.Zip.ArchiveEntry

protected ArchiveEntry(string name, CompressionSettings compressionSettings, Stream source, FileAttributes fileAttributes, FileSystemInfo fileInfo = null)

พารามิเตอร์

name string

ชื่อเอนทรี

compressionSettings CompressionSettings

การตั้งค่าสำหรับการบีบอัดหรือการคลายบีบอัด

source Stream

Stream ที่มีข้อมูลเอนทรีที่ต้องบีบอัดหรือคลายบีบอัด

fileAttributes FileAttributes

คุณสมบัติจากระบบไฟล์

fileInfo FileSystemInfo

ข้อมูลไฟล์หรือไดเร็กทอรีที่เอนทรีอิงตาม

คุณสมบัติ

Comment

รับความคิดเห็นของเอนทรีภายในคลังข้อมูล

public string Comment { get; protected set; }

ค่า Property

string

CompressedSize

รับขนาดของไฟล์ที่ถูกบีบอัด

public ulong CompressedSize { get; }

ค่า Property

ulong

CompressionSettings

รับการตั้งค่าสำหรับการบีบอัดหรือการคลายบีบอัด

public CompressionSettings CompressionSettings { get; }

ค่า Property

CompressionSettings

DataSource

แหล่งข้อมูลสำหรับเอนทรีหากเอนทรีถูกเพิ่มไปยังคลังข้อมูล ไม่ใช่ถูกแยกออก

public Stream DataSource { get; }

ค่า Property

Stream

หมายเหตุ

ก่อนที่จะกำหนด ค่าแหล่งข้อมูลจะเป็น null แหล่งข้อมูลนี้อาจถูกกำหนดภายใน Archive.Save ในบางกรณี

FileAttributes

รับคุณสมบัติไฟล์จากระบบโฮสต์

protected FileAttributes FileAttributes { get; }

ค่า Property

FileAttributes

IsDirectory

รับค่าที่บ่งชี้ว่าเอนทรีแสดงถึงไดเร็กทอรีหรือไม่

public bool IsDirectory { get; }

ค่า Property

bool

ModificationTime

รับหรือกำหนดวันที่และเวลาที่แก้ไขล่าสุด

public DateTime ModificationTime { get; set; }

ค่า Property

DateTime

Name

รับชื่อของเอนทรีภายในคลังข้อมูล

public string Name { get; protected set; }

ค่า Property

string

UncompressedSize

รับขนาดของไฟล์ต้นฉบับ

public ulong UncompressedSize { get; }

ค่า Property

ulong

วิธีการ

Extract(string, string)

แยกเอนทรีไปยังระบบไฟล์ตามเส้นทางที่ให้ไว้

public FileInfo Extract(string path, string password = null)

พารามิเตอร์

path string

เส้นทางไปยังไฟล์ปลายทาง หากไฟล์มีอยู่แล้ว จะถูกเขียนทับ

password string

รหัสผ่านสำหรับการถอดรหัส (ไม่บังคับ)

คืนค่า

FileInfo

ข้อมูลไฟล์ของไฟล์ที่ประกอบขึ้น

ตัวอย่าง

แยกเอนทรีสองรายการจากคลัง zip แต่ละรายการมีรหัสผ่านของตัวเอง

using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract("first.bin", "first_pass");
        archive.Entries[1].Extract("second.bin", "second_pass");
    }
}

ข้อยกเว้น

ArgumentNullException

path เป็น null

SecurityException

ผู้เรียกไม่สามารถเข้าถึงได้ตามที่กำหนด

ArgumentException

path ว่างเปล่า มีเพียงช่องว่าง หรือมีอักขระที่ไม่ถูกต้อง

UnauthorizedAccessException

การเข้าถึงไฟล์ path ถูกปฏิเสธ

PathTooLongException

path ที่ระบุ ชื่อไฟล์ หรือทั้งสองอย่างเกินความยาวสูงสุดที่กำหนดโดยระบบ เช่น บนแพลตฟอร์ม Windows เส้นทางต้องมีความยาวน้อยกว่า 248 ตัวอักษร และชื่อไฟล์ต้องมีความยาวน้อยกว่า 260 ตัวอักษร

NotSupportedException

ไฟล์ที่ path มีเครื่องหมายโคลอน (:) อยู่กลางสตริง

FileNotFoundException

ไม่พบไฟล์

DirectoryNotFoundException

เส้นทางที่ระบุไม่ถูกต้อง เช่น อยู่บนไดรฟ์ที่ไม่ได้แมพ

IOException

ไฟล์เปิดอยู่แล้ว

InvalidDataException

ข้อมูลเสียหาย - หรือ - การตรวจสอบ CRC หรือ MAC ล้มเหลวสำหรับเอนทรี

Extract(Stream, string)

แยกเอนทรีไปยัง stream ที่ให้ไว้

public void Extract(Stream destination, string password = null)

พารามิเตอร์

destination Stream

stream ปลายทาง ต้องสามารถเขียนได้

password string

รหัสผ่านสำหรับการถอดรหัส (ไม่บังคับ)

ตัวอย่าง

แยกเอนทรีของคลัง zip ด้วยรหัสผ่าน

using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract(httpResponseStream, "p@s$");
    }
}

ข้อยกเว้น

InvalidDataException

ข้อมูลเสียหาย - หรือ - การตรวจสอบ CRC หรือ MAC ล้มเหลวสำหรับเอนทรี

IOException

แหล่งข้อมูลเสียหายหรือไม่สามารถอ่านได้

ArgumentException

destination ไม่รองรับการเขียน

Open(string)

เปิดเอนทรีสำหรับการแยกและให้ stream ที่มีเนื้อหาของเอนทรีที่ถูกคลายบีบอัด

public Stream Open(string password = null)

พารามิเตอร์

password string

รหัสผ่านสำหรับการถอดรหัส (ไม่บังคับ)

คืนค่า

Stream

stream ที่แสดงถึงเนื้อหาของเอนทรี

ตัวอย่าง

การใช้งาน: Stream decompressed = entry.Open();

.NET 4.0 และสูงกว่า - ใช้เมธอด Stream.CopyTo: decompressed.CopyTo(httpResponse.OutputStream)

.NET 3.5 และก่อนหน้า - คัดลอกไบต์ด้วยตนเอง:

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

#### หมายเหตุ

<p>อ่านจาก stream เพื่อรับเนื้อหาต้นฉบับของไฟล์ ดูส่วนตัวอย่าง</p>

#### ข้อยกเว้น

[InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception)

คลังข้อมูลอยู่ในสถานะที่ไม่ถูกต้อง

### <a id="Aspose_Zip_ArchiveEntry_CompressionProgressed"></a> CompressionProgressed

เกิดขึ้นเมื่อมีการบีบอัดส่วนหนึ่งของ raw stream

```csharp
public event EventHandler<progresseventargs> CompressionProgressed

ประเภทเหตุการณ์

EventHandler<ProgressEventArgs&gt;

ตัวอย่าง

archive.Entries[0].CompressionProgressed += (s, e) =&gt; { int percent = (int)((100 * (long)e.ProceededBytes) / entrySourceStream.Length); };

หมายเหตุ

ผู้ส่งเหตุการณ์คืออินสแตนซ์ของ Aspose.Zip.ArchiveEntry

ExtractionProgressed

เกิดขึ้นเมื่อมีการแยกส่วนหนึ่งของ raw stream

public event EventHandler<progresseventargs> ExtractionProgressed

ประเภทเหตุการณ์

EventHandler<ProgressEventArgs&gt;

ตัวอย่าง

archive.Entries[0].ExtractionProgressed += (s, e) =&gt; { int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize); };

หมายเหตุ

ผู้ส่งเหตุการณ์คืออินสแตนซ์ของ Aspose.Zip.ArchiveEntry

 แบบไทย