Giter VIP home page Giter VIP logo

archivedatar3's Introduction

ArchiveDataR3

[Ru]ZipStorer класс для архивации ваших данных в .Net 4.0 и выше.

Оригинал ZipStorer класс был взят от сюда: https://github.com/jaime-olivares/zipstorer
Моя статья по архивации с этими классами: https://teletype.in/@r3xq1/ArchiveDataR3

Класс полностью прокомментирован на Русскоязычную аудиторию, чтобы было понятно кто не знаком с Английским языком.

[Заметки]
Всегда используйте using ( при этом не вызывайте Close(); )
За место ковычек "" пишите так: string.Empty;
Ни в коем случае не вызывайте null иначе будет крашить с ошибками.
Есть небольшие проблемы с [RU] кодировкой файлов при сборе, за меcто Русского текста заменяется ____ подчёркиванием.

Пример использования

private static readonly string Desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // Путь к рабочему столу.
private static readonly string TargetFile = Path.Combine(Desktop, "11.jpg"); // Путь к файлу на рабочем столе.
private static readonly string ZipArchive = Path.Combine(Desktop, "MyArchive.zip"); // Путь куда будет сохраняться .Zip архив с данными.

Для массового добавления файлов

// Создаём массив файлов для сбора
var filegrabber = new string[] 
{ 
   Path.Combine(Desktop, "Arch.png"), 
   Path.Combine(Desktop, "11.jpg") 
};
            
using var zip = ZipStorer.Create(ZipArchive, string.Empty); // Второй аргумент это комментарии к архиву.
zip.EncodeUTF8 = true; // Задаём кодировку. ( Не обязательно )
foreach (string files in filepath) // Перебираем все файлы в цикле.
{
  if (File.Exists(files)) // Проверяем каждый файл
  {
     zip?.AddFile(mode, files, Path.GetFileName(files), string.Empty); // Добавляем в архив каждый файл из цикла.
  }
}

Вызов:

ZipR3.AddMassFile(ZipArchive, filegrabber, ZipStorer.Compression.Store);

Для массового добавления папок

// Создаём массив папок для сбора
var dirgrabber = new string[] 
{ 
   Path.Combine(Desktop, "Dir One"), 
   Path.Combine(Desktop, "Dir Two") 
};

using var zipdir = ZipStorer.Create(ZipArchive, string.Empty);
foreach (string dir in datapath) // Проходимся по циклу
{
  if (Directory.Exists(dir)) // Проверяем каждую папку
  {
     zipdir?.AddDirectory(mode, dir, string.Empty); // Добавляем каждую папку(с файлами внутри) в архив
  }
}

Вызов:

 ZipR3.AddMassDirectory(ZipArchive, dirgrabber, ZipStorer.Compression.Store);

archivedatar3's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.