Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
/ SharpCompressUWP Public archive

SharpCompress UWP Port, Universal compression library

License

Notifications You must be signed in to change notification settings

basharast/SharpCompressUWP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Universal compression library for UWP projects
Source | Original Project



About

SharpCompress is a fully managed C# library to deal with many compression types and formats.

The project originally developed by Adam Hathcock

Based on the Original SharpCompress 0.30.1

Current Progress

In progress, currently only two main functions ported

  • WriteEntryToDirectory

  • AddAllFromDirectory

  • More functions in progress

Target

It will support any UWP project (build 14393+)

but if you want to compile your project with .NETNativeToolChain use 16299+ as min target

Usage

You will be able for now to compress or decompress with specific functions

Compress

var zipFile = await folder.CreateFileAsync("testFile.zip", CreationCollisionOption.ReplaceExisting);
using (var stream = await zipFile.OpenStreamForWriteAsync())
using (var archive = ZipArchive.Create())
{
  //To avoid UI block run this code into Task
  
  await archive.AddAllFromDirectory(targetFolder);
  //AddAllFromDirectory can extended to:
  //AddAllFromDirectory(storageFolder, string[] searchPattern, SearchOption.AllDirectories, IProgress<int> progress, bool IncludeRootFolder, CancellationTokenSource cancellationTokenSource)
  //IProgress<int> will report how many file queued
  
  
  archive.SaveTo(stream);
  //SaveTo can extended to:
  //SaveTo(Stream stream, IProgress<Dictionary<string, long>> progress, CancellationTokenSource cancellationTokenSource)
  //IProgress<Dictionary<string, long>> will provide file name / size like below:
  //string fileName = value.FirstOrDefault().Key;
  //string size = value.FirstOrDefault().Value.ToFileSize();
  
}            

Extract

Stream zipStream = await zipFile.OpenStreamForReadAsync();
using (var zipArchive = ArchiveFactory.Open(zipStream)){
//It should support 7z, zip, rar, gz, tar
var reader = zipArchive.ExtractAllEntries();

//Bind progress event
reader.EntryExtractionProgress += (sender, e) =>
{
  var entryProgress = e.ReaderProgress.PercentageReadExact;
  var sizeProgress = e.ReaderProgress.BytesTransferred.ToFileSize();
};              

//Extract files
while (reader.MoveToNextEntry()){
  if (!reader.Entry.IsDirectory){
    await reader.WriteEntryToDirectory(destinationFolder, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
    //WriteEntryToDirectory can extended to:
    //WriteEntryToDirectory(folder, options, cancellationTokenSource)
    //                                       ^^^^^^^^^^^^^^^^^^^^^^^
    //it will help to terminate the current entry directly if cancellation requested
  }
}
}

Credits

Developed by Adam Hathcock

UWP Port Bashar Astifan

About

SharpCompress UWP Port, Universal compression library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages