Class ArchiveEntry
Namespace: Aspose.Zip
Assembly: Aspose.Zip.dll (25.1.0)
แสดงถึงไฟล์เดียวภายในคลังข้อมูล
public abstract class ArchiveEntry : IArchiveFileEntry
การสืบทอด
ที่สืบทอด
ArchiveEntryEncrypted, ArchiveEntryPlain
การใช้งาน
สมาชิกที่สืบทอด
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>
วิธีการคืนค่า 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
CompressedSize
รับขนาดของไฟล์ที่ถูกบีบอัด
public ulong CompressedSize { get; }
ค่า Property
CompressionSettings
รับการตั้งค่าสำหรับการบีบอัดหรือการคลายบีบอัด
public CompressionSettings CompressionSettings { get; }
ค่า Property
DataSource
แหล่งข้อมูลสำหรับเอนทรีหากเอนทรีถูกเพิ่มไปยังคลังข้อมูล ไม่ใช่ถูกแยกออก
public Stream DataSource { get; }
ค่า Property
หมายเหตุ
ก่อนที่จะกำหนด ค่าแหล่งข้อมูลจะเป็น null แหล่งข้อมูลนี้อาจถูกกำหนดภายใน Archive.Save
ในบางกรณี
FileAttributes
รับคุณสมบัติไฟล์จากระบบโฮสต์
protected FileAttributes FileAttributes { get; }
ค่า Property
IsDirectory
รับค่าที่บ่งชี้ว่าเอนทรีแสดงถึงไดเร็กทอรีหรือไม่
public bool IsDirectory { get; }
ค่า Property
ModificationTime
รับหรือกำหนดวันที่และเวลาที่แก้ไขล่าสุด
public DateTime ModificationTime { get; set; }
ค่า Property
Name
รับชื่อของเอนทรีภายในคลังข้อมูล
public string Name { get; protected set; }
ค่า Property
UncompressedSize
รับขนาดของไฟล์ต้นฉบับ
public ulong UncompressedSize { get; }
ค่า Property
วิธีการ
Extract(string, string)
แยกเอนทรีไปยังระบบไฟล์ตามเส้นทางที่ให้ไว้
public FileInfo Extract(string path, string password = null)
พารามิเตอร์
path
string
เส้นทางไปยังไฟล์ปลายทาง หากไฟล์มีอยู่แล้ว จะถูกเขียนทับ
password
string
รหัสผ่านสำหรับการถอดรหัส (ไม่บังคับ)
คืนค่า
ข้อมูลไฟล์ของไฟล์ที่ประกอบขึ้น
ตัวอย่าง
แยกเอนทรีสองรายการจากคลัง 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");
}
}
ข้อยกเว้น
path
เป็น null
ผู้เรียกไม่สามารถเข้าถึงได้ตามที่กำหนด
path
ว่างเปล่า มีเพียงช่องว่าง หรือมีอักขระที่ไม่ถูกต้อง
การเข้าถึงไฟล์ path
ถูกปฏิเสธ
path
ที่ระบุ ชื่อไฟล์ หรือทั้งสองอย่างเกินความยาวสูงสุดที่กำหนดโดยระบบ เช่น บนแพลตฟอร์ม Windows เส้นทางต้องมีความยาวน้อยกว่า 248 ตัวอักษร และชื่อไฟล์ต้องมีความยาวน้อยกว่า 260 ตัวอักษร
ไฟล์ที่ path
มีเครื่องหมายโคลอน (:) อยู่กลางสตริง
ไม่พบไฟล์
เส้นทางที่ระบุไม่ถูกต้อง เช่น อยู่บนไดรฟ์ที่ไม่ได้แมพ
ไฟล์เปิดอยู่แล้ว
ข้อมูลเสียหาย - หรือ - การตรวจสอบ 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$");
}
}
ข้อยกเว้น
ข้อมูลเสียหาย - หรือ - การตรวจสอบ CRC หรือ MAC ล้มเหลวสำหรับเอนทรี
แหล่งข้อมูลเสียหายหรือไม่สามารถอ่านได้
destination
ไม่รองรับการเขียน
Open(string)
เปิดเอนทรีสำหรับการแยกและให้ stream ที่มีเนื้อหาของเอนทรีที่ถูกคลายบีบอัด
public Stream Open(string password = null)
พารามิเตอร์
password
string
รหัสผ่านสำหรับการถอดรหัส (ไม่บังคับ)
คืนค่า
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 < (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>
ตัวอย่าง
archive.Entries[0].CompressionProgressed += (s, e) => { int percent = (int)((100 * (long)e.ProceededBytes) / entrySourceStream.Length); };
หมายเหตุ
ผู้ส่งเหตุการณ์คืออินสแตนซ์ของ Aspose.Zip.ArchiveEntry
ExtractionProgressed
เกิดขึ้นเมื่อมีการแยกส่วนหนึ่งของ raw stream
public event EventHandler<progresseventargs> ExtractionProgressed
ประเภทเหตุการณ์
EventHandler<ProgressEventArgs>
ตัวอย่าง
archive.Entries[0].ExtractionProgressed += (s, e) => { int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize); };
หมายเหตุ
ผู้ส่งเหตุการณ์คืออินสแตนซ์ของ Aspose.Zip.ArchiveEntry