locked
Compress file size without using Zip? RRS feed

  • Question

  • Hi all,

    Is it possible to compress file size without using zip?

    if possible then how can we compress the file?

    thanks


    sumitk

    Wednesday, January 30, 2013 6:43 AM

Answers

  • If "compact file size" (reducing storage size on NTFS) is desirable for you, just save the file normally and then call File.GetAttributes(filePath), set the FileAttributes.Compressed and call File.SetAttributes(filePath, <altered attributes>). The NTFS driver will do the remaining works.

    To read such file, just read it the normal way. No special code is needed.

    The best thing about this method is that once you marked the Compressed attribute for a folder, anything you save into that folder will be automagically compressed by NTFS driver, no special handling is required. (Other than the fact that you need to reserve space on harddisk for decompression of such files)

    • Edited by cheong00Editor Wednesday, January 30, 2013 8:11 AM
    • Marked as answer by Sumitk.cdac Wednesday, January 30, 2013 10:27 AM
    Wednesday, January 30, 2013 8:04 AM
    Answerer

All replies

  • hi Sumit,

    You can compress by using DeflateStream Class


    PS.Shakeer Hussain

    Wednesday, January 30, 2013 7:19 AM
  • Try Below link it will solve your problem,,

    http://msdn.microsoft.com/en-us/library/system.io.packaging.zippackage%28v=vs.100%29.aspx


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". CRMHUNT http://crmhunt.com

    • Proposed as answer by CRM HUNT Wednesday, January 30, 2013 7:36 AM
    Wednesday, January 30, 2013 7:36 AM
  • If "compact file size" (reducing storage size on NTFS) is desirable for you, just save the file normally and then call File.GetAttributes(filePath), set the FileAttributes.Compressed and call File.SetAttributes(filePath, <altered attributes>). The NTFS driver will do the remaining works.

    To read such file, just read it the normal way. No special code is needed.

    The best thing about this method is that once you marked the Compressed attribute for a folder, anything you save into that folder will be automagically compressed by NTFS driver, no special handling is required. (Other than the fact that you need to reserve space on harddisk for decompression of such files)

    • Edited by cheong00Editor Wednesday, January 30, 2013 8:11 AM
    • Marked as answer by Sumitk.cdac Wednesday, January 30, 2013 10:27 AM
    Wednesday, January 30, 2013 8:04 AM
    Answerer
  • Depends on what you mean with "Without using zip".

    There is a bulk of other compression methods/format out there. .gzip, .rar, .7zp

    For example 7zip claims/was said to "compress .rar better then Winrar". .rar is only how the resulting file has to be structured so it can be decompressed. I could write a rar file without compressing anything - and it could still be "decompressed" reliably.

    If your main sorrow is the ease of access (you want it to be compressed without having to do anything special to read/write it):

    There are several Stream Classes with compression support. As they all are derived from System.IO.stream like FileStream or MemoryStream, they can just be used as one:*

    http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx
    http://msdn.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx

    Finally ZipArchive allows you to treat .zip files similar to directories and ZipArchiveEntry allows you to read/write a file inside a .zip archive like a file in a normal directory
    And those are part of the Framework itsself.

    *asuming they allow reading, writing and seeking. I don't know, you have to instance one to be sure

    Wednesday, January 30, 2013 8:26 AM
  • Hi Christopher84,

    i just want to compress my files without using any .Extension(i.e zip,.gzip,.rar).

    i want to simply compress my file size.


    sumitk

    Wednesday, January 30, 2013 9:31 AM
  • You want to do it using any C# application or any third party software..

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". CRMHUNT http://crmhunt.com

    Wednesday, January 30, 2013 9:58 AM
  • As cheong pointed out the NTFS Filesystem itself has compression features. Asuming the File isn't store on a network folder, simply setting the File Attribute "Compressed" to true will reduce the size it takes on the disk. This compression is fairly good for textfiles (including sourcecode, XML files, and pre-2007 office dokuments) and every other naturally inefficient/uncompressed format. The NTFS Driver of your system will handle compression/decompression on the fly.

    Wednesday, January 30, 2013 10:16 AM