C# GZipStream CanSeek

Description

GZipStream CanSeek Gets a value indicating whether the stream supports seeking.

Syntax

GZipStream.CanSeek has the following syntax.


public override bool CanSeek { get; }

Example


using System;/*from  w  ww  . ja v  a2  s  . c  o m*/
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;

class Program
{
    static void Main(string[] args)
    {
        string directoryPath = @"c:\users\";
        DirectoryInfo directorySelected = new DirectoryInfo(directoryPath);

        foreach (FileInfo fileToCompress in directorySelected.EnumerateFiles())
        {
            Compress(fileToCompress);
        }
    }

    public static void Compress(FileInfo fileToCompress)
    {
        using (FileStream originalFileStream = fileToCompress.OpenRead())
        {
            if ((File.GetAttributes(fileToCompress.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fileToCompress.Extension != ".gz")
            {
                using (FileStream compressedFileStream = File.Create(fileToCompress.FullName + ".gz"))
                {
                    using (GZipStream compressionStream = new GZipStream(compressedFileStream, CompressionLevel.Fastest))
                    {
                        Console.WriteLine(compressionStream.CanSeek);
                    }
                }
            }
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO.Compression »




DeflateStream
GZipStream
ZipArchive
ZipArchiveEntry
ZipFile
ZipFileExtensions