Decompressing a file using DeflateStream (C#) : DeflateStream « File Directory « ASP.NET Tutorial






<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.IO.Compression" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        string filename = Server.MapPath("Data.zip");

        FileStream infile = File.OpenRead(filename);
        DeflateStream deflateStream = new DeflateStream(infile, CompressionMode.Decompress);
        byte[] buffer = new byte[infile.Length + 100];

        int offset = 0;
        int totalCount = 0;
        while (true)
        {
            int bytesRead = deflateStream.Read(buffer, offset, 100);
            if (bytesRead == 0)
            { break; }

            offset += bytesRead;
            totalCount += bytesRead;
        }

        FileStream outfile = File.Create(Path.ChangeExtension(filename, "txt"));
        outfile.Write(buffer, 0, buffer.Length);
        outfile.Close();

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>








10.13.DeflateStream
10.13.1.Decompressing a file using DeflateStream (C#)
10.13.2.Decompressing a file using DeflateStream (VB)