Bagikan melalui


GZipStream Konstruktor

Definisi

Menginisialisasi instans baru kelas GZipStream.

Overload

GZipStream(Stream, CompressionLevel)

Menginisialisasi instans baru kelas GZipStream dengan menggunakan tingkat aliran dan kompresi yang ditentukan.

GZipStream(Stream, CompressionMode)

Menginisialisasi instans baru kelas GZipStream dengan menggunakan mode aliran dan kompresi yang ditentukan.

GZipStream(Stream, CompressionLevel, Boolean)

Menginisialisasi instans baru kelas GZipStream dengan menggunakan tingkat aliran dan kompresi yang ditentukan, dan secara opsional membiarkan aliran terbuka.

GZipStream(Stream, CompressionMode, Boolean)

Menginisialisasi instans baru kelas GZipStream dengan menggunakan mode aliran dan kompresi yang ditentukan, dan secara opsional membiarkan aliran terbuka.

GZipStream(Stream, ZLibCompressionOptions, Boolean)

Menginisialisasi instans baru kelas GZipStream dengan menggunakan aliran yang ditentukan, opsi pemadatan, dan secara opsional membiarkan aliran terbuka.

GZipStream(Stream, CompressionLevel)

Sumber:
GZipStream.cs
Sumber:
GZipStream.cs
Sumber:
GZipStream.cs

Menginisialisasi instans baru kelas GZipStream dengan menggunakan tingkat aliran dan kompresi yang ditentukan.

public:
 GZipStream(System::IO::Stream ^ stream, System::IO::Compression::CompressionLevel compressionLevel);
public GZipStream (System.IO.Stream stream, System.IO.Compression.CompressionLevel compressionLevel);
new System.IO.Compression.GZipStream : System.IO.Stream * System.IO.Compression.CompressionLevel -> System.IO.Compression.GZipStream
Public Sub New (stream As Stream, compressionLevel As CompressionLevel)

Parameter

stream
Stream

Aliran tempat data terkompresi ditulis.

compressionLevel
CompressionLevel

Salah satu nilai enumerasi yang menunjukkan apakah akan menekankan kecepatan atau efisiensi pemadatan saat mengompresi data ke aliran.

Pengecualian

stream null.

Aliran tidak mendukung operasi tulis seperti pemadatan. (Properti CanWrite pada objek stream false.)

Keterangan

Anda menggunakan konstruktor ini ketika Anda ingin menentukan apakah efisiensi atau kecepatan kompresi lebih penting untuk instans kelas GZipStream.

Overload konstruktor ini menggunakan mode kompresi Compress. Untuk mengatur mode kompresi ke nilai lain, gunakan GZipStream(Stream, CompressionMode) atau GZipStream(Stream, CompressionMode, Boolean) kelebihan beban.

Berlaku untuk

GZipStream(Stream, CompressionMode)

Sumber:
GZipStream.cs
Sumber:
GZipStream.cs
Sumber:
GZipStream.cs

Menginisialisasi instans baru kelas GZipStream dengan menggunakan mode aliran dan kompresi yang ditentukan.

public:
 GZipStream(System::IO::Stream ^ stream, System::IO::Compression::CompressionMode mode);
public GZipStream (System.IO.Stream stream, System.IO.Compression.CompressionMode mode);
new System.IO.Compression.GZipStream : System.IO.Stream * System.IO.Compression.CompressionMode -> System.IO.Compression.GZipStream
Public Sub New (stream As Stream, mode As CompressionMode)

Parameter

stream
Stream

Aliran tempat data terkompresi ditulis atau dari data mana yang akan didekompresi dibaca.

mode
CompressionMode

Salah satu nilai enumerasi yang menunjukkan apakah akan mengompresi data ke aliran atau mendekompresi data dari aliran.

Pengecualian

stream null.

mode bukan nilai enumerasi CompressionMode yang valid.

-atau-

CompressionMode Compress dan CanWritefalse.

-atau-

CompressionMode Decompress dan CanReadfalse.

Contoh

Contoh berikut menunjukkan cara mengatur mode pemadatan saat membuat objek GZipStream.

using System;
using System.IO;
using System.IO.Compression;

public class FileCompressionModeExample
{
    private const string Message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
    private const string OriginalFileName = "original.txt";
    private const string CompressedFileName = "compressed.gz";
    private const string DecompressedFileName = "decompressed.txt";

    public static void Run()
    {
        CreateFileToCompress();
        CompressFile();
        DecompressFile();
        PrintResults();
        DeleteFiles();

        /*
         Output:

            The original file 'original.txt' is 445 bytes. Contents: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

            The compressed file 'compressed.gz' is 283 bytes.

            The decompressed file 'decompressed.txt' is 445 bytes. Contents: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
         */
    }

    private static void CreateFileToCompress() => File.WriteAllText(OriginalFileName, Message);

    private static void CompressFile()
    {
        using FileStream originalFileStream = File.Open(OriginalFileName, FileMode.Open);
        using FileStream compressedFileStream = File.Create(CompressedFileName);
        using var compressor = new GZipStream(compressedFileStream, CompressionMode.Compress);
        originalFileStream.CopyTo(compressor);
    }

    private static void DecompressFile()
    {
        using FileStream compressedFileStream = File.Open(CompressedFileName, FileMode.Open);
        using FileStream outputFileStream = File.Create(DecompressedFileName);
        using var decompressor = new GZipStream(compressedFileStream, CompressionMode.Decompress);
        decompressor.CopyTo(outputFileStream);
    }

    private static void PrintResults()
    {
        long originalSize = new FileInfo(OriginalFileName).Length;
        long compressedSize = new FileInfo(CompressedFileName).Length;
        long decompressedSize = new FileInfo(DecompressedFileName).Length;

        Console.WriteLine($"The original file '{OriginalFileName}' is {originalSize} bytes. Contents: \"{File.ReadAllText(OriginalFileName)}\"");
        Console.WriteLine($"The compressed file '{CompressedFileName}' is {compressedSize} bytes.");
        Console.WriteLine($"The decompressed file '{DecompressedFileName}' is {decompressedSize} bytes. Contents: \"{File.ReadAllText(DecompressedFileName)}\"");
    }

    private static void DeleteFiles()
    {
        File.Delete(OriginalFileName);
        File.Delete(CompressedFileName);
        File.Delete(DecompressedFileName);
    }
}
open System.IO
open System.IO.Compression

let message =
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

let OriginalFileName = "original.txt"
let CompressedFileName = "compressed.gz"
let DecompressedFileName = "decompressed.txt"

let createFileToCompress () =
    File.WriteAllText(OriginalFileName, message)

let compressFile () =
    use originalFileStream = File.Open(OriginalFileName, FileMode.Open)
    use compressedFileStream = File.Create CompressedFileName
    use compressor = new GZipStream(compressedFileStream, CompressionMode.Compress)
    originalFileStream.CopyTo compressor

let decompressFile () =
    use compressedFileStream = File.Open(CompressedFileName, FileMode.Open)
    use outputFileStream = File.Create DecompressedFileName
    use decompressor = new GZipStream(compressedFileStream, CompressionMode.Decompress)
    decompressor.CopyTo outputFileStream

let printResults () =
    let originalSize = FileInfo(OriginalFileName).Length
    let compressedSize = FileInfo(CompressedFileName).Length
    let decompressedSize = FileInfo(DecompressedFileName).Length

    printfn
        $"The original file '{OriginalFileName}' weighs {originalSize} bytes. Contents: \"{File.ReadAllText OriginalFileName}\""

    printfn $"The compressed file '{CompressedFileName}' weighs {compressedSize} bytes."

    printfn
        $"The decompressed file '{DecompressedFileName}' weighs {decompressedSize} bytes. Contents: \"{File.ReadAllText DecompressedFileName}\""

let deleteFiles () =
    File.Delete OriginalFileName
    File.Delete CompressedFileName
    File.Delete DecompressedFileName

createFileToCompress ()
compressFile ()
decompressFile ()
printResults ()
deleteFiles ()

// Output:
//     The original file 'original.txt' weighs 445 bytes. Contents: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
//
//     The compressed file 'compressed.gz' weighs 283 bytes.
//
//     The decompressed file 'decompressed.txt' weighs 445 bytes. Contents: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Imports System
Imports System.IO
Imports System.IO.Compression

Public Class FileCompressionModeExample
    Private Const Message As String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    Private Const OriginalFileName As String = "original.txt"
    Private Const CompressedFileName As String = "compressed.gz"
    Private Const DecompressedFileName As String = "decompressed.txt"

    Public Shared Sub Main()
        CreateFileToCompress()
        CompressFile()
        DecompressFile()
        PrintResults()
        DeleteFiles()

        ' Output:
        '   The original file 'original.txt' weighs 445 bytes. Contents: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

        '   The compressed file 'compressed.gz' weighs 283 bytes.

        '   The decompressed file 'decompressed.txt' weighs 445 bytes. Contents: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    End Sub

    Private Shared Sub CreateFileToCompress()
        File.WriteAllText(OriginalFileName, Message)
    End Sub

    Private Shared Sub CompressFile()
        Using originalFileStream As FileStream = File.Open(OriginalFileName, FileMode.Open)
            Using compressedFileStream As FileStream = File.Create(CompressedFileName)
                Using compressor = New GZipStream(compressedFileStream, CompressionMode.Compress)
                    originalFileStream.CopyTo(compressor)
                End Using
            End Using
        End Using
    End Sub

    Private Shared Sub DecompressFile()
        Using compressedFileStream As FileStream = File.Open(CompressedFileName, FileMode.Open)
            Using outputFileStream As FileStream = File.Create(DecompressedFileName)
                Using decompressor = New GZipStream(compressedFileStream, CompressionMode.Decompress)
                    decompressor.CopyTo(outputFileStream)
                End Using
            End Using
        End Using
    End Sub

    Private Shared Sub PrintResults()
        Dim originalSize As Long = New FileInfo(OriginalFileName).Length
        Dim compressedSize As Long = New FileInfo(CompressedFileName).Length
        Dim decompressedSize As Long = New FileInfo(DecompressedFileName).Length

        Console.WriteLine($"The original file '{OriginalFileName}' weighs {originalSize} bytes. Contents: ""{File.ReadAllText(OriginalFileName)}""")
        Console.WriteLine($"The compressed file '{CompressedFileName}' weighs {compressedSize} bytes.")
        Console.WriteLine($"The decompressed file '{DecompressedFileName}' weighs {decompressedSize} bytes. Contents: ""{File.ReadAllText(DecompressedFileName)}""")
    End Sub

    Private Shared Sub DeleteFiles()
        File.Delete(OriginalFileName)
        File.Delete(CompressedFileName)
        File.Delete(DecompressedFileName)
    End Sub
End Class

Keterangan

Secara default, GZipStream memiliki aliran yang mendasar, jadi menutup parameter stream juga menutup aliran yang mendasar. Perhatikan bahwa status aliran yang mendasar dapat memengaruhi kegunaan aliran. Selain itu, tidak ada pemeriksaan eksplisit yang dilakukan, jadi tidak ada pengecualian tambahan yang dilemparkan saat instans baru dibuat.

Jika instans kelas GZipStream dibuat dengan parameter mode sama dengan Compress dan tidak ada tindakan lebih lanjut yang terjadi, aliran akan muncul sebagai file terkompresi yang valid dan kosong.

Secara default, tingkat kompresi diatur ke Optimal ketika mode kompresi Compress.

Berlaku untuk

GZipStream(Stream, CompressionLevel, Boolean)

Sumber:
GZipStream.cs
Sumber:
GZipStream.cs
Sumber:
GZipStream.cs

Menginisialisasi instans baru kelas GZipStream dengan menggunakan tingkat aliran dan kompresi yang ditentukan, dan secara opsional membiarkan aliran terbuka.

public:
 GZipStream(System::IO::Stream ^ stream, System::IO::Compression::CompressionLevel compressionLevel, bool leaveOpen);
public GZipStream (System.IO.Stream stream, System.IO.Compression.CompressionLevel compressionLevel, bool leaveOpen);
new System.IO.Compression.GZipStream : System.IO.Stream * System.IO.Compression.CompressionLevel * bool -> System.IO.Compression.GZipStream
Public Sub New (stream As Stream, compressionLevel As CompressionLevel, leaveOpen As Boolean)

Parameter

stream
Stream

Aliran tempat data terkompresi ditulis.

compressionLevel
CompressionLevel

Salah satu nilai enumerasi yang menunjukkan apakah akan menekankan kecepatan atau efisiensi pemadatan saat mengompresi data ke aliran.

leaveOpen
Boolean

true membiarkan objek stream terbuka setelah membuang objek GZipStream; jika tidak, false.

Pengecualian

stream null.

Aliran tidak mendukung operasi tulis seperti pemadatan. (Properti CanWrite pada objek stream false.)

Contoh

Contoh berikut menunjukkan cara mengatur tingkat kompresi saat membuat objek GZipStream dan cara membiarkan aliran terbuka.

using System;
using System.IO;
using System.IO.Compression;
using System.Text;

public static class MemoryWriteReadExample
{
    private const string Message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
    private static readonly byte[] s_messageBytes = Encoding.ASCII.GetBytes(Message);

    public static void Run()
    {
        Console.WriteLine($"The original string length is {s_messageBytes.Length} bytes.");
        using var stream = new MemoryStream();
        CompressBytesToStream(stream);
        Console.WriteLine($"The compressed stream length is {stream.Length} bytes.");
        int decompressedLength = DecompressStreamToBytes(stream);
        Console.WriteLine($"The decompressed string length is {decompressedLength} bytes, same as the original length.");
        /*
         Output:
            The original string length is 445 bytes.
            The compressed stream length is 282 bytes.
            The decompressed string length is 445 bytes, same as the original length.
        */
    }

    private static void CompressBytesToStream(Stream stream)
    {
        using var compressor = new GZipStream(stream, CompressionLevel.SmallestSize, leaveOpen: true);
        compressor.Write(s_messageBytes, 0, s_messageBytes.Length);
    }

    private static int DecompressStreamToBytes(Stream stream)
    {
        stream.Position = 0;
        int bufferSize = 512;
        byte[] buffer = new byte[bufferSize];
        using var gzipStream = new GZipStream(stream, CompressionMode.Decompress);

        int totalRead = 0;
        while (totalRead < buffer.Length)
        {
            int bytesRead = gzipStream.Read(buffer.AsSpan(totalRead));
            if (bytesRead == 0) break;
            totalRead += bytesRead;
        }

        return totalRead;
    }
}
open System.IO
open System.IO.Compression
open System.Text

let message =
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

let s_messageBytes = Encoding.ASCII.GetBytes message

let compressBytesToStream stream =
    use compressor =
        new GZipStream(stream, CompressionLevel.SmallestSize, leaveOpen = true)

    compressor.Write(s_messageBytes, 0, s_messageBytes.Length)

let decompressStreamToBytes (stream: Stream) =
    stream.Position <- 0
    let bufferSize = 512
    let decompressedBytes = Array.zeroCreate bufferSize
    use decompressor = new GZipStream(stream, CompressionMode.Decompress)
    decompressor.Read(decompressedBytes, 0, bufferSize)

[<EntryPoint>]
let main _ =
    printfn $"The original string length is {s_messageBytes.Length} bytes."
    use stream = new MemoryStream()
    compressBytesToStream stream
    printfn $"The compressed stream length is {stream.Length} bytes."
    let decompressedLength = decompressStreamToBytes stream
    printfn $"The decompressed string length is {decompressedLength} bytes, same as the original length."
    0

// Output:
//     The original string length is 445 bytes.
//     The compressed stream length is 282 bytes.
//     The decompressed string length is 445 bytes, same as the original length.
Imports System.IO
Imports System.IO.Compression
Imports System.Text

Module MemoryWriteReadExample
    Private Const Message As String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    Private ReadOnly s_messageBytes As Byte() = Encoding.ASCII.GetBytes(Message)

    Sub Main()
        Console.WriteLine($"The original string length is {s_messageBytes.Length} bytes.")

        Using stream = New MemoryStream()
            CompressBytesToStream(stream)
            Console.WriteLine($"The compressed stream length is {stream.Length} bytes.")
            Dim decompressedLength As Integer = DecompressStreamToBytes(stream)
            Console.WriteLine($"The decompressed string length is {decompressedLength} bytes, same as the original length.")
        End Using
        ' Output:
        '   The original string length is 445 bytes.
        '   The compressed stream length is 282 bytes.
        '   The decompressed string length is 445 bytes, same as the original length.
    End Sub

    Private Sub CompressBytesToStream(ByVal stream As Stream)
        Using compressor = New GZipStream(stream, CompressionLevel.SmallestSize, leaveOpen:=True)
            compressor.Write(s_messageBytes, 0, s_messageBytes.Length)
        End Using
    End Sub

    Private Function DecompressStreamToBytes(ByVal stream As Stream) As Integer
        stream.Position = 0
        Dim bufferSize As Integer = 512
        Dim decompressedBytes As Byte() = New Byte(bufferSize - 1) {}
        Using decompressor = New GZipStream(stream, CompressionMode.Decompress)
            Dim length As Integer = decompressor.Read(decompressedBytes, 0, bufferSize)
            Return length
        End Using
    End Function
End Module

Keterangan

Anda menggunakan konstruktor ini ketika Anda ingin menentukan apakah efisiensi atau kecepatan kompresi lebih penting untuk instans kelas GZipStream, dan apakah akan membiarkan objek stream terbuka setelah membuang objek GZipStream.

Overload konstruktor ini menggunakan mode kompresi Compress. Untuk mengatur mode kompresi ke nilai lain, gunakan GZipStream(Stream, CompressionMode) atau GZipStream(Stream, CompressionMode, Boolean) kelebihan beban.

Berlaku untuk

GZipStream(Stream, CompressionMode, Boolean)

Sumber:
GZipStream.cs
Sumber:
GZipStream.cs
Sumber:
GZipStream.cs

Menginisialisasi instans baru kelas GZipStream dengan menggunakan mode aliran dan kompresi yang ditentukan, dan secara opsional membiarkan aliran terbuka.

public:
 GZipStream(System::IO::Stream ^ stream, System::IO::Compression::CompressionMode mode, bool leaveOpen);
public GZipStream (System.IO.Stream stream, System.IO.Compression.CompressionMode mode, bool leaveOpen);
new System.IO.Compression.GZipStream : System.IO.Stream * System.IO.Compression.CompressionMode * bool -> System.IO.Compression.GZipStream
Public Sub New (stream As Stream, mode As CompressionMode, leaveOpen As Boolean)

Parameter

stream
Stream

Aliran tempat data terkompresi ditulis atau dari data mana yang akan didekompresi dibaca.

mode
CompressionMode

Salah satu nilai enumerasi yang menunjukkan apakah akan mengompresi data ke aliran atau mendekompresi data dari aliran.

leaveOpen
Boolean

true membiarkan aliran terbuka setelah membuang objek GZipStream; jika tidak, false.

Pengecualian

stream null.

mode bukan nilai CompressionMode yang valid.

-atau-

CompressionMode Compress dan CanWritefalse.

-atau-

CompressionMode Decompress dan CanReadfalse.

Keterangan

Secara default, GZipStream memiliki aliran yang mendasar, jadi menutup parameter stream juga menutup aliran yang mendasar. Status aliran yang mendasar dapat memengaruhi kegunaan aliran. Selain itu, tidak ada pemeriksaan eksplisit yang dilakukan, jadi tidak ada pengecualian tambahan yang dilemparkan saat instans baru dibuat.

Jika instans kelas GZipStream dibuat dengan parameter mode sama dengan Compress dan tidak ada tindakan lebih lanjut yang terjadi, aliran akan muncul sebagai file terkompresi yang valid dan kosong.

Secara default, tingkat kompresi diatur ke Optimal ketika mode kompresi Compress.

Berlaku untuk

GZipStream(Stream, ZLibCompressionOptions, Boolean)

Menginisialisasi instans baru kelas GZipStream dengan menggunakan aliran yang ditentukan, opsi pemadatan, dan secara opsional membiarkan aliran terbuka.

public GZipStream (System.IO.Stream stream, System.IO.Compression.ZLibCompressionOptions compressionOptions, bool leaveOpen = false);
new System.IO.Compression.GZipStream : System.IO.Stream * System.IO.Compression.ZLibCompressionOptions * bool -> System.IO.Compression.GZipStream
Public Sub New (stream As Stream, compressionOptions As ZLibCompressionOptions, Optional leaveOpen As Boolean = false)

Parameter

stream
Stream

Aliran tempat data terkompresi ditulis.

compressionOptions
ZLibCompressionOptions

Opsi untuk menyempurnakan aliran kompresi.

leaveOpen
Boolean

true membiarkan objek stream terbuka setelah membuang objek GZipStream; jika tidak, false.

Pengecualian

stream atau compressionOptionsnull.

Berlaku untuk