EXtremeZip 2021.6.10 → 2021.7.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/exuz +7 -7
- data/bin/exz +10 -7
- data/lib/extremeunzip.zzaqsu.rb +114 -121
- data/lib/extremezip.zzaqsv.rb +174 -177
- metadata +21 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db78a6e233cc5036a528a97794377882998cd83868015f108151739a019c7f9
|
4
|
+
data.tar.gz: 9dd9762163a9e310e534b24a8231f5e588cf3497699767d887dbdc91650b350f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb2aebbdb9f8584a7d80878a8ddaae134bd77284f056b4446cfe5f4a886df1d07b169e5609c8f0d610aa60312847b8a62183b845767461175e68682de51c62e8
|
7
|
+
data.tar.gz: 3338d07a08f7347d7b4d5070f64959d6b5e685600bf6be96fd9e42212505649cd579f7a4cac41414fe110f202dc6a3cabe413dd1c076b373c328ee9fe4bfb100
|
data/bin/exuz
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'extremeunzip.zzaqsu'
|
4
4
|
|
5
|
-
if
|
6
|
-
else
|
7
|
-
$rootPath=ARGV[0]
|
8
|
-
|
9
|
-
exuzObject=ExtremeUnZip.new
|
10
|
-
|
11
|
-
exuzObject.exuz($rootPath)
|
5
|
+
if ARGV.empty? # 未指定命令行参数。
|
6
|
+
else # 指定了命令行参数。
|
7
|
+
$rootPath = ARGV[0] # 记录要打包的目录树的根目录。
|
8
|
+
|
9
|
+
exuzObject = ExtremeUnZip.new # 解压对象
|
10
|
+
|
11
|
+
exuzObject.exuz($rootPath) # 解压
|
12
12
|
end
|
data/bin/exz
CHANGED
@@ -2,11 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'extremezip.zzaqsv'
|
4
4
|
|
5
|
-
if
|
6
|
-
else
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
if ARGV.empty? # 未指定命令行参数。
|
6
|
+
else # 指定了命令行参数。
|
7
|
+
puts("process id: #{Process.pid}"); # Debug
|
8
|
+
|
9
|
+
|
10
|
+
$rootPath = ARGV[0] # 记录要打包的目录树的根目录。
|
11
|
+
|
12
|
+
exzObject = ExtremeZip.new # 创建压缩对象
|
13
|
+
|
14
|
+
exzObject.exz($rootPath) # 压缩
|
12
15
|
end
|
data/lib/extremeunzip.zzaqsu.rb
CHANGED
@@ -8,150 +8,143 @@ require 'lzma'
|
|
8
8
|
require 'get_process_mem'
|
9
9
|
|
10
10
|
def checkMemoryUsage(lineNumber)
|
11
|
-
mem= GetProcessMem.new
|
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
|
-
compressedVfsDataList.each do |currentCompressed| #一块块地解压
|
44
|
-
puts("data block counter: #{dataBlockCounter}") #Debug
|
11
|
+
mem = GetProcessMem.new
|
12
|
+
|
13
|
+
puts("#{lineNumber} , Memory: #{mem.mb}"); # Debug
|
14
|
+
end # def checkMemoryUsage
|
15
|
+
|
16
|
+
# 根据版本号,提取VFS数据内容
|
17
|
+
def extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion)
|
18
|
+
victoriaFreshData = '' # 解压后的数据块整体
|
19
|
+
dataFileName = 'victoriafreshdata.w' # 数据文件名
|
20
|
+
dataFile = {} # 数据文件对象
|
21
|
+
|
22
|
+
if (fileVersion == 14) # 14版本
|
23
|
+
compressedVfsData = wholeCbor['vfsData'] # 获取压缩后的数据内容
|
24
|
+
|
25
|
+
victoriaFreshData = LZMA.decompress(compressedVfsData) # 解压缩数据内容
|
26
|
+
|
27
|
+
dataFile = File.open(dataFileName, 'wb') # 打开文件
|
28
|
+
|
29
|
+
dataFile.syswrite(victoriaFreshData) # 写入内容
|
30
|
+
|
31
|
+
dataFile.close # 关闭文件
|
32
|
+
elsif (fileVersion >= 30) # 30以上版本
|
33
|
+
compressedVfsDataList = wholeCbor['vfsDataList'] # 获取压缩后的数据块列表
|
34
|
+
|
35
|
+
puts("data block amont: #{compressedVfsDataList.length}") # Debug
|
36
|
+
|
37
|
+
dataBlockCounter = 0 # Data block counter
|
38
|
+
|
39
|
+
dataFile = File.open(dataFileName, 'wb') # 打开文件
|
40
|
+
|
41
|
+
compressedVfsDataList.each do |currentCompressed| # 一块块地解压
|
42
|
+
puts("data block counter: #{dataBlockCounter}") # Debug
|
45
43
|
checkMemoryUsage(34)
|
46
44
|
|
47
|
-
currentRawData=LZMA.decompress(currentCompressed)
|
48
|
-
|
49
|
-
dataFile.syswrite(currentRawData)
|
50
|
-
|
51
|
-
# victoriaFreshData=victoriaFreshData+currentRawData #追加
|
52
|
-
# victoriaFreshData << currentRawData #追加
|
53
|
-
|
54
|
-
puts("byte size: #{victoriaFreshData.bytesize}") #debug.
|
55
|
-
|
56
|
-
dataBlockCounter
|
57
|
-
end #compressedVfsDataList.each do |currentCompressed|
|
58
|
-
|
59
|
-
dataFile.close
|
60
|
-
end #if (fileVersion==14) #14版本
|
61
|
-
|
62
|
-
|
63
|
-
end #def extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) #根据版本号,提取VFS数据内容
|
64
|
-
|
65
|
-
def extractVfsDataWithVersion(wholeCbor, fileVersion)
|
66
|
-
victoriaFreshData=''
|
67
|
-
|
68
|
-
if (fileVersion==14) #14版本
|
69
|
-
compressedVfsData=wholeCbor['vfsData']
|
70
|
-
|
71
|
-
victoriaFreshData=LZMA.decompress(compressedVfsData)
|
72
|
-
elsif (fileVersion>=30) #30以上版本
|
73
|
-
compressedVfsDataList=wholeCbor['vfsDataList']
|
74
|
-
|
75
|
-
puts("data block amont: #{compressedVfsDataList.length}") #Debug
|
76
|
-
|
77
|
-
dataBlockCounter=0 #Data block counter
|
78
|
-
|
79
|
-
compressedVfsDataList.each do |currentCompressed|
|
80
|
-
puts("data block counter: #{dataBlockCounter}") #Debug
|
45
|
+
currentRawData = LZMA.decompress(currentCompressed) # 解压这一块
|
46
|
+
|
47
|
+
dataFile.syswrite(currentRawData) # 写入内容
|
48
|
+
|
49
|
+
# victoriaFreshData=victoriaFreshData+currentRawData #追加
|
50
|
+
# victoriaFreshData << currentRawData #追加
|
51
|
+
|
52
|
+
puts("byte size: #{victoriaFreshData.bytesize}") # debug.
|
53
|
+
|
54
|
+
dataBlockCounter += 1 # count
|
55
|
+
end # compressedVfsDataList.each do |currentCompressed|
|
56
|
+
|
57
|
+
dataFile.close # 关闭文件
|
58
|
+
end # if (fileVersion==14) #14版本
|
59
|
+
|
60
|
+
dataFileName # 返回解压后的数据块整体
|
61
|
+
end # def extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) #根据版本号,提取VFS数据内容
|
62
|
+
|
63
|
+
def extractVfsDataWithVersion(wholeCbor, fileVersion) # 根据版本号,提取VFS数据内容
|
64
|
+
victoriaFreshData = '' # 解压后的数据块整体
|
65
|
+
|
66
|
+
if (fileVersion == 14) # 14版本
|
67
|
+
compressedVfsData = wholeCbor['vfsData'] # 获取压缩后的数据内容
|
68
|
+
|
69
|
+
victoriaFreshData = LZMA.decompress(compressedVfsData) # 解压缩数据内容
|
70
|
+
elsif (fileVersion >= 30) # 30以上版本
|
71
|
+
compressedVfsDataList = wholeCbor['vfsDataList'] # 获取压缩后的数据块列表
|
72
|
+
|
73
|
+
puts("data block amont: #{compressedVfsDataList.length}") # Debug
|
74
|
+
|
75
|
+
dataBlockCounter = 0 # Data block counter
|
76
|
+
|
77
|
+
compressedVfsDataList.each do |currentCompressed| # 一块块地解压
|
78
|
+
puts("data block counter: #{dataBlockCounter}") # Debug
|
81
79
|
checkMemoryUsage(34)
|
82
80
|
|
83
|
-
currentRawData=LZMA.decompress(currentCompressed)
|
81
|
+
currentRawData = LZMA.decompress(currentCompressed) # 解压这一块
|
82
|
+
|
83
|
+
# victoriaFreshData=victoriaFreshData+currentRawData #追加
|
84
|
+
victoriaFreshData << currentRawData # 追加
|
84
85
|
|
85
|
-
#
|
86
|
-
victoriaFreshData << currentRawData #追加
|
86
|
+
puts("byte size: #{victoriaFreshData.bytesize}") # debug.
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
return victoriaFreshData #返回解压后的数据块整体
|
88
|
+
dataBlockCounter += 1 # count
|
89
|
+
end # compressedVfsDataList.each do |currentCompressed|
|
90
|
+
end # if (fileVersion==14) #14版本
|
91
|
+
|
92
|
+
victoriaFreshData # 返回解压后的数据块整体
|
95
93
|
end # extractVfsDataWithVersion(wholeCbor, fileVersion) #根据版本号,提取VFS数据内容
|
96
94
|
|
97
95
|
class ExtremeUnZip
|
98
|
-
|
96
|
+
# 解压
|
99
97
|
def exuz(rootPath)
|
100
|
-
wholeFileContent=File.read(rootPath)
|
101
|
-
|
98
|
+
wholeFileContent = File.read(rootPath) # 最终文件内容
|
99
|
+
|
102
100
|
checkMemoryUsage(60)
|
103
|
-
|
104
|
-
puts wholeFileContent.class #debug
|
105
|
-
|
106
|
-
wholeCborByteArray=wholeFileContent[4..-1]
|
101
|
+
|
102
|
+
puts wholeFileContent.class # debug
|
103
|
+
|
104
|
+
wholeCborByteArray = wholeFileContent[4..-1] # 从第5个到末尾
|
107
105
|
checkMemoryUsage(65)
|
108
|
-
|
109
|
-
|
106
|
+
|
110
107
|
# puts wholeCborByteArray #Debug.
|
111
|
-
|
108
|
+
|
112
109
|
checkMemoryUsage(70)
|
113
|
-
wholeCbor=CBOR.decode(wholeCborByteArray)
|
110
|
+
wholeCbor = CBOR.decode(wholeCborByteArray) # 解码
|
114
111
|
# wholeCbor=wholeCborByteArray.from_cbor #解码CBOR
|
115
|
-
|
112
|
+
|
116
113
|
# puts wholeCbor #Debug.
|
117
114
|
checkMemoryUsage(75)
|
118
|
-
|
119
|
-
fileVersion=wholeCbor['version']
|
120
|
-
|
121
|
-
puts 'fileVersion:' #Debug
|
115
|
+
|
116
|
+
fileVersion = wholeCbor['version'] # 获取版本号
|
117
|
+
|
118
|
+
puts 'fileVersion:' # Debug
|
122
119
|
checkMemoryUsage(80)
|
123
|
-
puts fileVersion #Debug.
|
124
|
-
|
125
|
-
|
126
|
-
if (fileVersion<14) #版本号过小
|
120
|
+
puts fileVersion # Debug.
|
121
|
+
|
122
|
+
if (fileVersion < 14) # 版本号过小
|
127
123
|
checkMemoryUsage(85)
|
128
|
-
puts 'file version too old'
|
129
|
-
else
|
130
|
-
compressedVfsMenu=wholeCbor['vfsMenu']
|
131
|
-
|
124
|
+
puts 'file version too old' # 报告错误
|
125
|
+
else # 版本号够大
|
126
|
+
compressedVfsMenu = wholeCbor['vfsMenu'] # 获取压缩后的目录内容
|
127
|
+
|
132
128
|
checkMemoryUsage(90)
|
133
|
-
replyByteArray=LZMA.decompress(compressedVfsMenu)
|
134
|
-
|
129
|
+
replyByteArray = LZMA.decompress(compressedVfsMenu) # 解码目录VFS字节数组内容
|
130
|
+
|
135
131
|
# puts replyByteArray #Debug
|
136
|
-
|
132
|
+
|
137
133
|
checkMemoryUsage(95)
|
138
134
|
# victoriaFreshData=extractVfsDataWithVersion(wholeCbor, fileVersion) #根据版本号,提取VFS数据内容
|
139
|
-
victoriaFreshDataFile=extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion)
|
140
|
-
|
135
|
+
victoriaFreshDataFile = extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) # 根据版本号,提取VFS数据内容
|
136
|
+
|
141
137
|
# puts victoriaFreshData #Debug
|
142
|
-
|
138
|
+
|
143
139
|
checkMemoryUsage(100)
|
144
|
-
$clipDownloader=VictoriaFresh.new
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
File.delete(fileToRemove) #删除文件
|
152
|
-
|
153
|
-
end #if (fileVersion<14) #版本号过小
|
154
|
-
|
155
|
-
end #def exuz(rootPath)
|
156
|
-
end #class ExtremeUnZip
|
140
|
+
$clipDownloader = VictoriaFresh.new # 创建下载器。
|
141
|
+
|
142
|
+
$clipDownloader.releaseFilesExternalDataFile(replyByteArray, victoriaFreshDataFile) # 释放各个文件
|
143
|
+
|
144
|
+
fileToRemove = File.new(victoriaFreshDataFile) # 要删除的文件
|
145
|
+
|
146
|
+
File.delete(fileToRemove) # 删除文件
|
157
147
|
|
148
|
+
end # if (fileVersion<14) #版本号过小
|
149
|
+
end # def exuz(rootPath)
|
150
|
+
end # class ExtremeUnZip
|
data/lib/extremezip.zzaqsv.rb
CHANGED
@@ -1,191 +1,188 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'victoriafresh'
|
4
|
-
require 'cbor'
|
5
|
-
require 'lzma'
|
6
|
-
require 'etc' #cpu amount
|
7
|
-
require 'cod'
|
5
|
+
require 'cbor' # CBOR
|
6
|
+
require 'lzma' # LZMA
|
7
|
+
require 'etc' # cpu amount
|
8
|
+
require 'cod'
|
8
9
|
require 'uuid'
|
9
10
|
require 'get_process_mem'
|
10
11
|
|
11
12
|
def checkMemoryUsage(lineNumber)
|
12
|
-
|
13
|
-
|
14
|
-
puts("#{lineNumber} , Memory: #{mem.mb}"); #Debug
|
15
|
-
|
16
|
-
end #def checkMemoryUsage
|
13
|
+
mem = GetProcessMem.new
|
17
14
|
|
15
|
+
puts("#{lineNumber} , Memory: #{mem.mb}, process id: #{Process.pid}"); # Debug
|
16
|
+
end # def checkMemoryUsage
|
18
17
|
|
19
18
|
class ExtremeZip
|
20
|
-
|
19
|
+
def initialize
|
20
|
+
@wholeCbor = {} # 整个CBOR结构
|
21
|
+
@vfsDataList = [] # 数据块压缩块列表
|
22
|
+
@filePartCounter = 0 # 文件分块计数器
|
23
|
+
@responsePipeList = [] # 任务回复管道列表
|
24
|
+
@processIdList = [] # 子进程编号列表。
|
25
|
+
|
26
|
+
@maxSubProcessAmount = Etc.nprocessors # 获取最大的子进程个数
|
27
|
+
|
28
|
+
@dataBlockLength = 33554432 # 数据块单元长度, 32MiB
|
29
|
+
|
30
|
+
@clipDownloader = VictoriaFresh.new # 创建下载器。
|
31
|
+
|
32
|
+
@clipDownloader.diskFlush = true # 向磁盘写入缓存
|
33
|
+
@clipDownloader.diskMultiFile = true # 写多个磁盘文件
|
34
|
+
@clipDownloader.diskFileName = 'victoriafreshdata.v.' # 磁盘文件名前缀
|
35
|
+
@clipDownloader.diskFlushSize = @dataBlockLength # 磁盘文件大小
|
36
|
+
end # def initialize
|
37
|
+
|
38
|
+
# 压缩目录数据。
|
39
|
+
def compressVfsMenu(victoriaFresh)
|
40
|
+
replyByteArray = victoriaFresh.to_cbor # #打包成字节数组。
|
41
|
+
|
42
|
+
# 压缩目录数据并放入CBOR:
|
43
|
+
compressedVfsMenu = LZMA.compress(replyByteArray) # 压缩目录数据
|
44
|
+
|
45
|
+
@wholeCbor['vfsMenu'] = compressedVfsMenu # 加入目录
|
46
|
+
end # compressVfsMenu(victoriaFresh) # 压缩目录数据。
|
47
|
+
|
48
|
+
# 加入基本文件信息
|
49
|
+
def addBasicFileInformation
|
50
|
+
@wholeCbor['version'] = 68 # 文件格式版本号
|
51
|
+
|
52
|
+
uuid = UUID.new # 获取生成器
|
53
|
+
@wholeCbor['uuid'] = uuid.generate # 指定本个压缩包的唯一编号
|
54
|
+
end # addBasicFileInformation # 加入基本文件信息
|
55
|
+
|
56
|
+
# 压缩
|
21
57
|
def exz(rootPath)
|
22
|
-
|
23
|
-
# dataBlockLength=16777216 #数据块单元长度, 16MiB
|
24
|
-
dataBlockLength=33554432 #数据块单元长度, 32MiB
|
25
|
-
# dataBlockLength=67108864 #数据块单元长度, 64MiB
|
26
|
-
|
27
|
-
checkMemoryUsage(75)
|
28
|
-
|
29
|
-
# dynamicBlockLength=victoriaFreshData.bytesize / Etc.nprocessors + 1 #尝试根据现在的任务计算出一个动态块长度。
|
30
|
-
dynamicBlockLength=dataBlockLength #尝试根据现在的任务计算出一个动态块长度。
|
31
|
-
|
32
|
-
|
33
|
-
checkMemoryUsage(80)
|
34
|
-
|
35
|
-
maxAcceptableDataBlockLength=52852*1024 #Max acceptable data block length
|
36
|
-
|
37
|
-
dataBlockLength=[dataBlockLength, dynamicBlockLength].max #取预定义的块长度和动态块长度中较大的那个来作为块长度。这样压缩比高一些
|
38
|
-
checkMemoryUsage(85)
|
39
|
-
|
40
|
-
dataBlockLength=[dataBlockLength, maxAcceptableDataBlockLength].min #Limit data block length, not to exceed max acceptable data block length.
|
41
|
-
|
42
|
-
puts("block length: #{dataBlockLength}") #Debug
|
43
|
-
|
44
|
-
|
45
|
-
$clipDownloader=VictoriaFresh.new #创建下载器。
|
46
|
-
|
47
|
-
$clipDownloader.diskFlush=true #向磁盘写入缓存
|
48
|
-
$clipDownloader.diskMultiFile=true #写多个磁盘文件
|
49
|
-
$clipDownloader.diskFileName='victoriafreshdata.v.' #磁盘文件名前缀
|
50
|
-
$clipDownloader.diskFlushSize=dataBlockLength #磁盘文件大小
|
51
|
-
|
52
|
-
|
53
|
-
checkMemoryUsage(25)
|
54
|
-
victoriaFresh,victoriaFreshData=$clipDownloader.checkOnce(rootPath) #打包该目录树。
|
55
|
-
|
56
|
-
#利用protobuf打包成字节数组:
|
57
|
-
replyByteArray="" #回复时使用的字节数组。
|
58
|
-
checkMemoryUsage(30)
|
59
|
-
replyByteArray=victoriaFresh.to_cbor ##打包成字节数组。
|
60
|
-
|
61
|
-
checkMemoryUsage(35)
|
62
|
-
#victoriaFreshFile=File.new("victoriafresh.v","wb") #创建文件。
|
63
|
-
#victoriaFreshFile.syswrite(replyByteArray) #写入文件。
|
64
|
-
|
65
|
-
#victoriaFreshFile.close #关闭文件。
|
66
|
-
checkMemoryUsage(40)
|
67
|
-
|
68
|
-
# victoriaFreshDataFile=File.new("victoriafreshdata.v","wb") #数据文件。
|
69
|
-
# victoriaFreshDataFile.syswrite(victoriaFreshData) #写入文件。
|
70
|
-
# victoriaFreshDataFile.close #关闭文件。
|
71
|
-
checkMemoryUsage(45)
|
72
|
-
|
73
|
-
|
74
|
-
wholeFileContent='' #最终文件内容
|
75
|
-
|
76
|
-
checkMemoryUsage(50)
|
77
|
-
wholeFileContent = wholeFileContent + 'exz' + "\0" #写入魔法文件头
|
78
|
-
|
79
|
-
wholeCbor={} #整个CBOR结构
|
80
|
-
wholeCbor['version']=68 #文件格式版本号
|
81
|
-
checkMemoryUsage(55)
|
82
|
-
|
83
|
-
uuid = UUID.new #获取生成器
|
84
|
-
generatedUuid=uuid.generate #生成唯一标识
|
85
|
-
wholeCbor['uuid']=generatedUuid #指定本个压缩包的唯一编号
|
86
|
-
checkMemoryUsage(60)
|
87
|
-
|
88
|
-
#压缩目录数据并放入CBOR:
|
89
|
-
compressedVfsMenu = LZMA.compress(replyByteArray) #压缩目录数据
|
90
|
-
|
91
|
-
checkMemoryUsage(65)
|
92
|
-
puts("compressed menu length: #{compressedVfsMenu.bytesize}") #Debug.
|
93
|
-
wholeCbor['vfsMenu']=compressedVfsMenu #加入目录
|
94
|
-
|
95
|
-
#压缩文件实体数据并放入CBOR:
|
96
|
-
checkMemoryUsage(70)
|
97
|
-
|
98
|
-
checkMemoryUsage(90)
|
99
|
-
|
100
|
-
|
101
|
-
processDataLength=0 #已处理的数据长度
|
102
|
-
|
103
|
-
checkMemoryUsage(95)
|
104
|
-
vfsDataList=[] #数据块压缩块列表
|
105
|
-
taskPipeList=[] #任务分配管道列表。
|
106
|
-
responsePipeList=[] #任务回复管道列表
|
107
|
-
processIdList = [] #记录到子进程列表中
|
108
|
-
checkMemoryUsage(100)
|
109
|
-
|
110
|
-
filePartAmount=$clipDownloader.currentDiskFlushSuffix #获取文件个数
|
111
|
-
|
112
|
-
filePartCounter=0 #文件计数器
|
113
|
-
|
114
|
-
while (filePartCounter < filePartAmount) #未处理完毕
|
115
|
-
currentBlockFile=File.new($clipDownloader.diskFileName+filePartCounter.to_s, 'rb') #打开文件
|
116
|
-
|
117
|
-
currentBlockData=currentBlockFile.read #读取全部内容
|
118
|
-
|
119
|
-
currentBlockFile.close #关闭文件
|
120
|
-
|
121
|
-
File.delete(currentBlockFile) #删除数据块文件
|
122
|
-
|
123
|
-
currentTaskPipe=Cod.pipe #任务分配管道
|
124
|
-
currentResponsePipe=Cod.pipe #任务回复管道
|
125
|
-
|
126
|
-
#记录管道:
|
127
|
-
taskPipeList << currentTaskPipe
|
128
|
-
responsePipeList << currentResponsePipe
|
129
|
-
p1 = fork do #复制出子进程
|
130
|
-
checkMemoryUsage(115)
|
131
|
-
currentBlockDataToCompress=currentBlockData #读取数据块
|
132
|
-
|
133
|
-
currentCompressedVfsData=LZMA.compress(currentBlockDataToCompress) #压缩当前块
|
134
|
-
|
135
|
-
checkMemoryUsage(120)
|
136
|
-
puts("compressed data length: #{currentCompressedVfsData.bytesize}") #Debug.
|
137
|
-
|
138
|
-
currentResponsePipe.put currentCompressedVfsData #将压缩后的数据块写入到回复管道中
|
139
|
-
|
140
|
-
checkMemoryUsage(125)
|
141
|
-
puts("finished #{Process.pid}") #Debug
|
142
|
-
end #p1 = fork do #复制出子进程
|
143
|
-
|
144
|
-
processDataLength=processDataLength + dataBlockLength #计数
|
145
|
-
checkMemoryUsage(130)
|
146
|
-
|
147
|
-
processIdList << p1 #记录到子进程列表中
|
148
|
-
|
149
|
-
filePartCounter=filePartCounter+1 #计数
|
150
|
-
end #while processDataLength < victoriaFreshData.byte_size do #未处理完毕
|
151
|
-
|
152
|
-
checkMemoryUsage(135)
|
153
|
-
processCounter=0 #子进程计数器
|
154
|
-
|
155
|
-
processIdList.each do |currentSubProcess|
|
156
|
-
puts("waiting #{currentSubProcess}") #Debug
|
157
|
-
checkMemoryUsage(140)
|
158
|
-
|
159
|
-
currentResponsePipe=responsePipeList[processCounter] #任务回复管道
|
160
|
-
|
161
|
-
currentCompressedVfsDataFromSubProcess=currentResponsePipe.get #读取压缩后数据
|
162
|
-
checkMemoryUsage(145)
|
163
|
-
|
164
|
-
Process.waitpid(currentSubProcess) #等待该个子进程
|
165
|
-
|
166
|
-
vfsDataList << currentCompressedVfsDataFromSubProcess #加入数据块列表中
|
167
|
-
checkMemoryUsage(150)
|
168
|
-
|
169
|
-
processCounter=processCounter+1 #子进程计数
|
170
|
-
end #processIdList.each do |currentSubProcess|
|
171
|
-
|
172
|
-
checkMemoryUsage(155)
|
173
|
-
wholeCbor['vfsDataList']=vfsDataList #加入数据
|
174
|
-
|
175
|
-
#序列化CBOR:
|
176
|
-
wholeCborByteArray=wholeCbor.to_cbor
|
177
|
-
checkMemoryUsage(160)
|
178
|
-
|
179
|
-
wholeFileContent = wholeFileContent + wholeCborByteArray
|
180
|
-
|
181
|
-
#写入文件:
|
182
|
-
checkMemoryUsage(165)
|
183
|
-
extremeZipOutputFile=File.new( victoriaFresh['name'] + '.exz', 'wb') #创建文件
|
184
|
-
extremeZipOutputFile.syswrite(wholeFileContent) #写入文件
|
185
|
-
extremeZipOutputFile.close #关闭文件
|
58
|
+
victoriaFresh, = @clipDownloader.checkOnce(rootPath) # 打包该目录树。
|
186
59
|
|
60
|
+
@filePartAmount = @clipDownloader.currentDiskFlushSuffix # 获取文件个数
|
61
|
+
|
62
|
+
compressVfsMenu(victoriaFresh) # 压缩目录数据。
|
63
|
+
|
64
|
+
addBasicFileInformation # 加入基本文件信息
|
65
|
+
|
66
|
+
processIdList, responsePipeList = launchSubProcesses # 启动子进程。
|
67
|
+
|
68
|
+
receiveCompressedVfsDataList(processIdList, responsePipeList) # 接收压缩后的数据块列表
|
69
|
+
|
70
|
+
checkMemoryUsage(155)
|
71
|
+
@wholeCbor['vfsDataList'] = @vfsDataList # 加入数据
|
72
|
+
|
73
|
+
wholeFileContent = 'exz' + "\0" + @wholeCbor.to_cbor # 追加CBOR字节数组
|
74
|
+
|
75
|
+
# 写入文件:
|
76
|
+
writeFile(wholeFileContent, victoriaFresh) # 写入文件内容
|
77
|
+
end # def exz(rootPath)
|
78
|
+
|
79
|
+
# 写入文件内容
|
80
|
+
def writeFile(wholeFileContent, victoriaFresh)
|
81
|
+
extremeZipOutputFile = File.new("#{victoriaFresh['name']}.exz", 'wb') # 创建文件
|
82
|
+
extremeZipOutputFile.syswrite(wholeFileContent) # 写入文件
|
83
|
+
extremeZipOutputFile.close # 关闭文件
|
84
|
+
end # writeFile(wholeFileContent, victoriaFresh) #写入文件内容
|
85
|
+
|
86
|
+
# 接收压缩后的数据块列表
|
87
|
+
def receiveCompressedVfsDataList(processIdList, responsePipeList)
|
88
|
+
processCounter = 0 # 子进程计数器
|
187
89
|
|
188
|
-
|
189
|
-
|
190
|
-
|
90
|
+
while (processCounter<@filePartAmount) # 并不是所有分块都被处理完毕了。
|
91
|
+
currentSubProcess=processIdList[processCounter] # 获取子进程对象
|
92
|
+
#processIdList.each do |currentSubProcess|
|
93
|
+
compressed = receiveFromSubProcess(currentSubProcess, responsePipeList, processCounter) # 从子进程中读取数据,并终止子进程
|
94
|
+
|
95
|
+
@vfsDataList << compressed # 加入数据块列表中
|
96
|
+
checkMemoryUsage(150)
|
97
|
+
|
98
|
+
processCounter += 1 # 子进程计数
|
99
|
+
|
100
|
+
if (@filePartCounter<@filePartAmount) # 还有一些分块尚未交给子进程进行处理
|
101
|
+
schedule1Block(@filePartCounter) # 再启动一个子进程
|
102
|
+
end # if (@filePartCounter<@filePartAmount) # 还有一些分块尚未交给子进程进行处理
|
103
|
+
end # processIdList.each do |currentSubProcess|
|
104
|
+
end # receiveCompressedVfsDataList # 接收压缩后的数据块列表
|
105
|
+
|
106
|
+
# 读取块文件内容
|
107
|
+
def readBlockFile(filePartCounter)
|
108
|
+
currentBlockFile = File.new(@clipDownloader.diskFileName + filePartCounter.to_s, 'rb') # 打开文件
|
109
|
+
|
110
|
+
currentBlockData = currentBlockFile.read # 读取全部内容
|
111
|
+
|
112
|
+
currentBlockFile.close # 关闭文件
|
113
|
+
|
114
|
+
File.delete(currentBlockFile) # 删除数据块文件
|
115
|
+
|
116
|
+
currentBlockData
|
117
|
+
end
|
118
|
+
|
119
|
+
# 计划一个块的压缩计算
|
120
|
+
def schedule1Block(filePartCounter)
|
121
|
+
currentBlockData = readBlockFile(filePartCounter) # 读取块文件内容
|
122
|
+
|
123
|
+
# currentTaskPipe = Cod.pipe # 任务分配管道
|
124
|
+
currentResponsePipe = Cod.pipe # 任务回复管道
|
125
|
+
|
126
|
+
puts("forking sub process, file part counter: #{filePartCounter}") # Debug.
|
127
|
+
|
128
|
+
p1 = fork do # 复制出子进程
|
129
|
+
compressInSubProcess(currentBlockData, currentResponsePipe) # 在子进程中具体执行的压缩代码
|
130
|
+
end # p1 = fork do #复制出子进程
|
131
|
+
|
132
|
+
# processDataLength += @dataBlockLength # 计数
|
133
|
+
checkMemoryUsage(130)
|
134
|
+
|
135
|
+
# 记录管道:
|
136
|
+
# taskPipeList << currentTaskPipe
|
137
|
+
@responsePipeList << currentResponsePipe # 记录回复管道
|
138
|
+
|
139
|
+
@processIdList << p1 # 记录到子进程列表中
|
140
|
+
|
141
|
+
@filePartCounter += 1 # 计数
|
142
|
+
|
143
|
+
[currentResponsePipe, p1]
|
144
|
+
end # schedule1Block(filePartCounter) # 计划一个块的压缩计算
|
145
|
+
|
146
|
+
# 启动子进程。
|
147
|
+
def launchSubProcesses
|
148
|
+
|
149
|
+
#while ((@filePartCounter < @filePartAmount) && (true)) # 未处理完毕,并且未达到最大子进程个数
|
150
|
+
while ((@filePartCounter < @filePartAmount) && (@filePartCounter<@maxSubProcessAmount)) # 未处理完毕,并且未达到最大子进程个数
|
151
|
+
currentResponsePipe, p1 = schedule1Block(@filePartCounter) # 计划一个块的压缩计算
|
152
|
+
|
153
|
+
end # while processDataLength < victoriaFreshData.byte_size do #未处理完毕
|
154
|
+
|
155
|
+
[@processIdList, @responsePipeList]
|
156
|
+
end # launchSubProcesses # 启动子进程。
|
157
|
+
|
158
|
+
# 在子进程中具体执行的压缩代码
|
159
|
+
def compressInSubProcess(currentBlockData, currentResponsePipe)
|
160
|
+
checkMemoryUsage(115) # Debug
|
161
|
+
currentBlockDataToCompress = currentBlockData # 读取数据块
|
162
|
+
|
163
|
+
currentCompressedVfsData = LZMA.compress(currentBlockDataToCompress) # 压缩当前块
|
164
|
+
|
165
|
+
checkMemoryUsage(120)
|
166
|
+
puts("compressed data length: #{currentCompressedVfsData.bytesize}") # Debug.
|
167
|
+
|
168
|
+
currentResponsePipe.put currentCompressedVfsData # 将压缩后的数据块写入到回复管道中
|
169
|
+
|
170
|
+
checkMemoryUsage(125)
|
171
|
+
puts("finished #{Process.pid}") # Debug
|
172
|
+
end # compressInSubProcess(currentBlockData, currentResponsePipe) # 在子进程中具体执行的压缩代码
|
173
|
+
|
174
|
+
# 从子进程中读取数据,并终止子进程
|
175
|
+
def receiveFromSubProcess(currentSubProcess, responsePipeList, processCounter)
|
176
|
+
puts("waiting #{currentSubProcess}") # Debug
|
177
|
+
checkMemoryUsage(140)
|
178
|
+
|
179
|
+
currentResponsePipe = responsePipeList[processCounter] # 任务回复管道
|
180
|
+
|
181
|
+
currentCompressedVfsDataFromSubProcess = currentResponsePipe.get # 读取压缩后数据
|
182
|
+
checkMemoryUsage(145)
|
183
|
+
|
184
|
+
Process.waitpid(currentSubProcess) # 等待该个子进程
|
191
185
|
|
186
|
+
currentCompressedVfsDataFromSubProcess
|
187
|
+
end # receiveFromSubProcess(currentSubProcess) # 从子进程中读取数据,并终止子进程
|
188
|
+
end # class ExtremeZip
|
metadata
CHANGED
@@ -1,91 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: EXtremeZip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2021.
|
4
|
+
version: 2021.7.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hxcan Cai
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: cod
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2021.5.28
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 0.6.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2021.5.28
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: 0.6.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: get_process_mem
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
33
|
+
version: 0.2.7
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
40
|
+
version: 0.2.7
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
42
|
+
name: ruby-lzma
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
45
|
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
47
|
+
version: 0.4.3
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.
|
54
|
+
version: 0.4.3
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
56
|
+
name: uuid
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
59
|
- - ">="
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
61
|
+
version: 2.3.9
|
68
62
|
type: :runtime
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
66
|
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
68
|
+
version: 2.3.9
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
70
|
+
name: VictoriaFreSh
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
78
72
|
requirements:
|
79
73
|
- - ">="
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
75
|
+
version: 2021.7.27
|
82
76
|
type: :runtime
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - ">="
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
82
|
+
version: 2021.7.27
|
89
83
|
description: Extreme zip.
|
90
84
|
email: caihuosheng@gmail.com
|
91
85
|
executables:
|
@@ -102,7 +96,7 @@ homepage: http://rubygems.org/gems/EXtremeZip
|
|
102
96
|
licenses:
|
103
97
|
- MIT
|
104
98
|
metadata: {}
|
105
|
-
post_install_message:
|
99
|
+
post_install_message:
|
106
100
|
rdoc_options: []
|
107
101
|
require_paths:
|
108
102
|
- lib
|
@@ -117,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
111
|
- !ruby/object:Gem::Version
|
118
112
|
version: '0'
|
119
113
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
121
|
-
signing_key:
|
114
|
+
rubygems_version: 3.0.3
|
115
|
+
signing_key:
|
122
116
|
specification_version: 4
|
123
117
|
summary: EXtremeZip
|
124
118
|
test_files: []
|