# Как разбить ZIP на части? C# приложение

**URL:** <https://forum.itvdn.com/t/kak-razbit-zip-na-chasti-c-prilozhenie/2775>\
**Category:** C#\
**Created:** [10.11.2018 19:58:32 UTC](https://forum.itvdn.com/t/kak-razbit-zip-na-chasti-c-prilozhenie/2775 "2018-11-10T19:58:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazenkomihail32](https://forum.itvdn.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@mazenkomihail32](https://forum.itvdn.com/u/mazenkomihail32)\
**Post date:** [10.11.2018 19:58:32 UTC](https://forum.itvdn.com/t/kak-razbit-zip-na-chasti-c-prilozhenie/2775/1 "2018-11-10T19:58:32Z")

</div>

В вопросе собственно озвучил всё: как программным путём разбить архив Zip на части? Программа на языке C#

---

<div class="post-metadata">

**Author:** ![volklenam](https://forum.itvdn.com/letter_avatar_proxy/v4/letter/v/eb8c5e/32.png) [@volklenam](https://forum.itvdn.com/u/volklenam)\
**Post date:** [10.11.2018 20:04:04 UTC](https://forum.itvdn.com/t/kak-razbit-zip-na-chasti-c-prilozhenie/2775/2 "2018-11-10T20:04:04Z")

</div>

Можете простым кодом вроде этого поделить уже готовый zip-файл на части:

```
public static void SplitFile(string source, long partSize, string destinationFormat, int firstFileNumber = 0)
{
    var sourceStream = File.OpenRead(source);

```
var buffer = new byte[80*1024];
var position = sourceStream.Position;
var fileNumber = firstFileNumber;

while (position < sourceStream.Length)
{
    var filename = String.Format(destinationFormat, fileNumber);

    using(var destinationStream = File.Create(filename))
    {
        var count = 0;

        do
        {
            count = sourceStream.Read(buffer, 0, (int)Math.Min(buffer.LongLength, partSize - destinationStream.Position));
            destinationStream.Write(buffer, 0, count);
            position = count;
        } while (count > 0);
    }

    fileNumber ;
}

```

}
```

```
SplitFile(
    source: @"C:\test\test.zip", 
    destinationFormat: @"C:\test\test.z{0 ![](https://forum.itvdn.com/content/images/emoticons/big-smile-emoticon-for-facebook.png)2}", 
    partSize: 100000*1024
    );
```

Если хотите сразу писать в несколько файлов, то конструктору ZipFile можно подавать в качестве аргумента экземпляры Stream/Filestream.
