-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMultiUploadZip.cs
More file actions
79 lines (54 loc) · 2.13 KB
/
MultiUploadZip.cs
File metadata and controls
79 lines (54 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.IO;
using System.IO.Compression;
using ByteSync.Common.Business.Misc;
using ByteSync.Common.Business.SharedFiles;
namespace ByteSync.Business.Synchronizations;
public class MultiUploadZip : IDisposable
{
public MultiUploadZip(string key, SharedFileDefinition sharedFileDefinition)
{
Key = key;
SharedFileDefinition = sharedFileDefinition;
SharedFileDefinition.IsMultiFileZip = true;
CreationDate = DateTime.Now;
Size = 0;
MemoryStream = new MemoryStream();
ZipArchive = new ZipArchive(MemoryStream, ZipArchiveMode.Create, true);
ActionGroupsIds = new List<string>();
FilesFullNames = new List<string>();
ActionsGroupIdsConcatenationLength = 0;
}
public string Key { get; }
public SharedFileDefinition SharedFileDefinition { get; }
public MemoryStream MemoryStream { get; }
public ZipArchive ZipArchive { get; }
public DateTime CreationDate { get; set; }
public long Size { get; private set; }
public int ActionsGroupIdsConcatenationLength { get; set; }
public List<string> ActionGroupsIds { get; set; }
public List<string> FilesFullNames { get; }
public bool CanAdd(FileInfo fileInfo, string actionsGroupId)
{
return
ActionGroupsIds.Count < 100 &&
ActionsGroupIdsConcatenationLength + actionsGroupId.Length + 5 < 25000 &&
Size + fileInfo.Length < 8 * SizeConstants.ONE_MEGA_BYTES;
}
public void AddEntry(FileInfo fileInfo, string actionsGroupId)
{
// https://stackoverflow.com/questions/22339260/how-do-i-add-files-to-an-existing-zip-archive
ZipArchive.CreateEntryFromFile(fileInfo.FullName, actionsGroupId, CompressionLevel.Fastest);
ActionGroupsIds.Add(actionsGroupId);
FilesFullNames.Add(fileInfo.FullName);
Size += fileInfo.Length;
ActionsGroupIdsConcatenationLength += actionsGroupId.Length + 5;
}
public void CloseZip()
{
ZipArchive.Dispose();
}
public void Dispose()
{
MemoryStream.Dispose();
}
}