VictoriaFreSh 2020.8.30 → 2021.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/victoriafresh.rb +240 -104
- data/victoriafresh.example.rb +8 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82c0c58d9b1daeffc9217b052959a5b67bf8547a2c51e58cb1fcfa4632fa1839
|
4
|
+
data.tar.gz: 341d862e0b92956637f54c8bd482e93e6ac0ad907a07c6532605008a4a5dc66a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dbc4bc708a277f8d2d4b5277aecd1ba9c5ecd5f3075dcf2d7ac68849bd526e0ef821e747b140fd82aa3f1b6f61860a30dc737dc57b75470eea635a49d412f41
|
7
|
+
data.tar.gz: 33db88a60ea8c9fd03562089312df3e6ddda6bfc41517d29177586a541278871e58075b4b9af057838935f8f089c3727373a682afc79a449a53de5b4377f34d8
|
data/lib/victoriafresh.rb
CHANGED
@@ -3,14 +3,40 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'cbor'
|
6
|
+
require 'get_process_mem'
|
6
7
|
|
7
8
|
# require File.dirname(__FILE__)+'/VictoriaFreSh/filemessage_pb.rb'
|
8
9
|
|
9
10
|
class VictoriaFresh
|
11
|
+
attr_accessor :diskFlushSize #累积了这么多的数据就向磁盘写入,以减少内存占用
|
12
|
+
attr_accessor :diskFileName #向磁盘写入数据时的文件名或前缀
|
13
|
+
attr_accessor :diskMultiFile #向磁盘写入时,是否要写多个文件
|
14
|
+
attr_accessor :diskFlush #要提前磁盘写入文件,以节省内存吗?
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@diskFlush=false #要向磁盘写入文件
|
18
|
+
@diskFlushSize=143212 #磁盘分块大小
|
19
|
+
@diskFileName='victoriafreshdata.v' #磁盘文件名
|
20
|
+
@diskMultiFile=false #磁盘整个文件,不是多个文件
|
21
|
+
@diskWriteFileObject={} #向磁盘写入文件的对象
|
22
|
+
@contentString="" #内容字符串
|
23
|
+
@contentPartArray=[] #内容片段数组
|
24
|
+
@currentDiskFlushSuffix=0 #当前的磁盘文件后缀
|
25
|
+
@bufferLength=0 #缓冲区总长度
|
26
|
+
end
|
27
|
+
|
28
|
+
def checkMemoryUsage(lineNumber)
|
29
|
+
mem= GetProcessMem.new
|
30
|
+
|
31
|
+
puts("#{lineNumber} , Memory: #{mem.mb}"); #Debug
|
32
|
+
|
33
|
+
end #def checkMemoryUsage
|
34
|
+
|
35
|
+
|
10
36
|
def releaseFiles(victoriaFreshPackagedFileString, contentString) #释放目录树
|
11
|
-
# packagedFile=Com::Stupidbeauty::Victoriafresh::FileMessage.decode(victoriaFreshPackagedFileString) #解码文件消息对象。
|
37
|
+
# packagedFile=Com::Stupidbeauty::Victoriafresh::FileMessage.decode(victoriaFreshPackagedFileString) #解码文件消息对象。
|
12
38
|
packagedFile=CBOR.decode(victoriaFreshPackagedFileString) #解码
|
13
|
-
|
39
|
+
|
14
40
|
|
15
41
|
puts packagedFile #Debug
|
16
42
|
|
@@ -33,6 +59,13 @@ class VictoriaFresh
|
|
33
59
|
|
34
60
|
FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
|
35
61
|
|
62
|
+
permissionNumber=packagedFile['permission'] #获取权限数字
|
63
|
+
|
64
|
+
if (permissionNumber.nil?) #不带权限字段
|
65
|
+
elsif #带权限字段
|
66
|
+
File.chmod(permissionNumber, pathToMake) #设置权限
|
67
|
+
end #if (permissionNumber.nil?) #不带权限字段
|
68
|
+
|
36
69
|
end #writeFile(pathPrefix, packagedFile, contentString) #写入文件
|
37
70
|
|
38
71
|
#创建符号链接
|
@@ -42,71 +75,75 @@ class VictoriaFresh
|
|
42
75
|
|
43
76
|
pathToMake=pathPrefix + '/' + packagedFile['name'] #构造文件名
|
44
77
|
|
45
|
-
# victoriaFreshDataFile=File.new(pathToMake , "wb") #数据文件。
|
46
|
-
# victoriaFreshDataFile.syswrite(victoriaFreshData) #写入文件。
|
47
|
-
# victoriaFreshDataFile.close #关闭文件。
|
48
|
-
#
|
49
|
-
# FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
|
50
|
-
|
78
|
+
# victoriaFreshDataFile=File.new(pathToMake , "wb") #数据文件。
|
79
|
+
# victoriaFreshDataFile.syswrite(victoriaFreshData) #写入文件。
|
80
|
+
# victoriaFreshDataFile.close #关闭文件。
|
81
|
+
#
|
82
|
+
# FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
|
83
|
+
|
51
84
|
puts("data: #{victoriaFreshData}, path: #{pathToMake}") #Debug
|
52
85
|
|
53
86
|
FileUtils.symlink(victoriaFreshData, pathToMake, force: true) #创建符号链接
|
54
87
|
|
55
|
-
|
88
|
+
permissionNumber=packagedFile['permission'] #获取权限数字
|
89
|
+
|
90
|
+
if (permissionNumber.nil?) #不带权限字段
|
91
|
+
elsif #带权限字段
|
92
|
+
# File.chmod(permissionNumber, pathToMake) #设置权限
|
93
|
+
begin #尝试修改链接本身的权限
|
94
|
+
File.lchmod(permissionNumber, pathToMake) #设置权限
|
95
|
+
rescue NotImplementedError #未实现
|
96
|
+
puts 'File.lchmod not implemented' #Debug
|
97
|
+
end #begin #尝试修改链接本身的权限
|
98
|
+
end #if (permissionNumber.nil?) #不带权限字段
|
56
99
|
end #def makeSymlink(pathPrefix, packagedFile, contentString) #创建符号链接
|
57
100
|
|
58
101
|
def getTimeObject(packagedFile) #构造时间戳对象
|
59
|
-
# seconds=packagedFile.timestamp.seconds #获取秒数
|
102
|
+
# seconds=packagedFile.timestamp.seconds #获取秒数
|
60
103
|
seconds=packagedFile['timestamp']['seconds'] #获取秒数
|
61
|
-
|
62
|
-
# microSeconds=packagedFile.timestamp.nanos/ 1000.0 #获取毫秒数
|
104
|
+
|
105
|
+
# microSeconds=packagedFile.timestamp.nanos/ 1000.0 #获取毫秒数
|
63
106
|
microSeconds=packagedFile['timestamp']['nanos'] / 1000.0 #获取毫秒数
|
64
107
|
|
65
108
|
timeObject=Time.at(seconds, microSeconds) #构造时间对象
|
66
|
-
|
109
|
+
|
67
110
|
end #getTimeObject(packagedFile) #构造时间戳对象
|
68
111
|
|
69
112
|
def makeDirectory(pathPrefix, packagedFile) #创建目录
|
70
113
|
timeObject=getTimeObject(packagedFile) #构造时间戳对象
|
71
|
-
|
72
114
|
|
73
|
-
puts 'mkdir' #Debug
|
74
115
|
|
75
|
-
#
|
116
|
+
# puts 'mkdir' #Debug
|
76
117
|
pathToMake=File.join(pathPrefix, packagedFile['name'])
|
77
118
|
|
78
|
-
puts pathToMake #Debug.
|
119
|
+
# puts pathToMake #Debug.
|
79
120
|
|
80
121
|
if (Dir.exist?(pathToMake)) #目录已经存在
|
81
122
|
else #目录 不存在
|
82
123
|
Dir.mkdir(pathToMake) #=> 0
|
83
124
|
end #if (Dir.exist?(pathToMake)) #目录已经存在
|
84
125
|
|
85
|
-
|
126
|
+
|
86
127
|
FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
|
87
|
-
|
128
|
+
|
129
|
+
permissionNumber=packagedFile['permission'] #获取权限数字
|
130
|
+
|
131
|
+
if (permissionNumber.nil?) #不带权限字段
|
132
|
+
elsif #带权限字段
|
133
|
+
File.chmod(permissionNumber, pathToMake) #设置权限
|
134
|
+
end #if (permissionNumber.nil?) #不带权限字段
|
88
135
|
end #makeDirectory(pathPrefix, packagedFile) #创建目录
|
89
136
|
|
90
137
|
def releaseFile( pathPrefix, packagedFile, contentString) #释放一个文件
|
91
|
-
# puts packagedFile.name #Debug
|
92
|
-
puts packagedFile['name'] #Debug
|
93
|
-
puts("content stirng length: #{contentString.bytesize}") #Debug
|
94
|
-
# puts packagedFile.timestamp #Debug
|
95
|
-
puts packagedFile['timestamp'] #Debug
|
96
|
-
|
97
|
-
# if packagedFile.is_file #是文件,则直接写入文件
|
98
138
|
if packagedFile['is_file'] #是文件,则直接写入文件
|
99
139
|
writeFile(pathPrefix, packagedFile, contentString) #写入文件
|
100
140
|
elsif packagedFile['is_symlink'] #是符号链接,则创建符号链接
|
101
141
|
makeSymlink(pathPrefix, packagedFile, contentString) #创建符号链接
|
102
|
-
# writeFile(pathPrefix, packagedFile, contentString) #写入文件
|
103
142
|
else #是目录,则创建目录,并递归处理
|
104
143
|
makeDirectory(pathPrefix, packagedFile) #创建目录
|
105
144
|
|
106
|
-
# direcotryPathPrefix=pathPrefix + '/' + packagedFile.name #构造针对该目录的路径前缀
|
107
145
|
direcotryPathPrefix=pathPrefix + '/' + packagedFile['name'] #构造针对该目录的路径前缀
|
108
146
|
|
109
|
-
# subFiles=packagedFile.sub_files #获取子文件列表。
|
110
147
|
subFiles=packagedFile['sub_files'] #获取子文件列表。
|
111
148
|
|
112
149
|
subFiles.each do |currentSubFile| #一个个子文件地释放
|
@@ -116,88 +153,187 @@ class VictoriaFresh
|
|
116
153
|
end #if packagedFile.is_file #是文件,则直接写入文件
|
117
154
|
end #def releaseFile(packagedFile, contentString) #释放一个文件
|
118
155
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
156
|
+
#考虑是否要向磁盘先输出内容
|
157
|
+
def assessDiskFlush(layer, isFinalPart=false)
|
158
|
+
if (@diskFlush) #要做磁盘写入
|
159
|
+
if (@bufferLength>=@diskFlushSize) #缓冲区总长度已经超过需要的文件长度
|
160
|
+
@contentString = @contentPartArray.join #重组成整个字符串
|
161
|
+
|
162
|
+
@contentPartArray.clear #清空数组
|
163
|
+
|
164
|
+
while (@contentString.length >= @diskFlushSize) #还有内容要写入
|
165
|
+
contentToWrite=@contentString[0, @diskFlushSize] #取出开头的一段
|
166
|
+
|
167
|
+
@contentString=@contentString[@diskFlushSize, @contentString.length-@diskFlushSize] #留下剩余的部分
|
168
|
+
|
169
|
+
if (@diskMultiFile) #多个磁盘文件
|
170
|
+
@diskWriteFileObject=File.new(@diskFileName+@currentDiskFlushSuffix.to_s, 'wb') #打开文件
|
171
|
+
|
172
|
+
@currentDiskFlushSuffix=@currentDiskFlushSuffix+1 #增加计数
|
173
|
+
|
174
|
+
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
175
|
+
|
176
|
+
@diskWriteFileObject.close
|
177
|
+
else #单个磁盘文件
|
178
|
+
|
179
|
+
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
180
|
+
|
181
|
+
@diskWriteFileObject.flush #写入磁盘
|
182
|
+
end #@currentDiskFlushSuffix
|
183
|
+
end #while (contentString.length >= @diskFlushSize) #还有内容要写入
|
184
|
+
|
185
|
+
@contentPartArray << @contentString #剩余部分重新加入数组中
|
186
|
+
@bufferLength=@contentString.length #重新记录缓冲区总长度
|
187
|
+
end #if (bufferLength>=@diskFlushSize) #缓冲区总长度已经超过需要的文件长度
|
188
|
+
|
189
|
+
if (isFinalPart) #是最后一部分
|
190
|
+
@contentString = @contentPartArray.join #重组成整个字符串
|
143
191
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
192
|
+
@contentPartArray.clear #清空字符串数组
|
193
|
+
@bufferLength=0 #缓冲区长度归零
|
194
|
+
|
195
|
+
contentToWrite=@contentString #要写入的内容
|
196
|
+
|
197
|
+
@contentString="" #字符串清空
|
198
|
+
|
199
|
+
if (@diskMultiFile) #多个磁盘文件
|
200
|
+
@diskWriteFileObject=File.new(@diskFileName+@currentDiskFlushSuffix.to_s, 'wb') #打开文件
|
201
|
+
|
202
|
+
@currentDiskFlushSuffix=@currentDiskFlushSuffix+1 #增加计数
|
203
|
+
|
204
|
+
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
205
|
+
|
206
|
+
@diskWriteFileObject.close
|
207
|
+
|
208
|
+
|
209
|
+
else #单个磁盘文件
|
210
|
+
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
211
|
+
|
212
|
+
@diskWriteFileObject.close #关闭文件
|
213
|
+
|
214
|
+
end #if (@diskMultiFile) #多个磁盘文件
|
215
|
+
end #if (isFinalPart) #是最后一部分
|
216
|
+
end #if (@diskFlush) #要做磁盘写入
|
217
|
+
end #contentString= assessDiskFlush(contentString) #考虑是否要向磁盘先输出内容
|
152
218
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
#
|
161
|
-
|
162
|
-
# puts("sub file: #{directoryPathName}, class: #{directoryPathName.class}, symlink: #{directoryPathName.symlink?}, expand_path: #{directoryPathName.expand_path}, file?: #{directoryPathName.file?}, read link: #{directoryPathName.readlink}") #Debug.
|
163
|
-
|
164
|
-
linkTarget=directoryPathName.readlink #获取链接目标
|
165
|
-
|
166
|
-
# 待续,设置内容长度。符号链接字符串的长度
|
167
|
-
packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
|
168
|
-
|
169
|
-
#读取文件内容:
|
170
|
-
# fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
171
|
-
contentString=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
172
|
-
# contentString=linkTarget.to_s.encode('UTF-8') #全部读取。
|
173
|
-
puts("encoding: #{contentString.encoding}") #Debug.
|
174
|
-
puts("content string: #{contentString}") #Debug
|
175
|
-
else #是目录。
|
176
|
-
contentString="" #容纳内容的字符串。
|
177
|
-
subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
|
178
|
-
|
179
|
-
# packagedFile.file_length=0 #本目录的内容长度。
|
180
|
-
packagedFile['file_length']=0 #本目录的内容长度。
|
181
|
-
|
182
|
-
directoryPathName.each_child do |subFile| #一个个文件地处理。
|
183
|
-
# puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
|
184
|
-
realPath=subFile.expand_path #获取绝对路径。
|
219
|
+
def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
|
220
|
+
if (@diskFlush) #要向磁盘写入文件
|
221
|
+
if (layer==0) #最外层
|
222
|
+
if (@diskMultiFile) #要写多个文件
|
223
|
+
else #不写多个文件
|
224
|
+
@diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
|
225
|
+
end #if (@diskMultiFile) #要写多个文件
|
226
|
+
end #if (layer==0) #最外层
|
227
|
+
end #if (@diskFlush) #要向磁盘写入文件s
|
185
228
|
|
186
|
-
|
229
|
+
packagedFile={} #创建文件消息对象。
|
187
230
|
|
188
|
-
packagedFile['sub_files']
|
231
|
+
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
189
232
|
|
190
|
-
|
233
|
+
directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
|
191
234
|
|
192
|
-
|
235
|
+
baseName=directoryPathName.basename.to_s #基本文件名。
|
193
236
|
|
194
|
-
|
237
|
+
packagedFile['name']=baseName #设置文件名。
|
195
238
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
239
|
+
isFile=directoryPathName.file? #是否是文件。
|
240
|
+
isSymLink=directoryPathName.symlink? #是否是符号链接
|
241
|
+
|
242
|
+
packagedFile['is_file']=isFile #设置属性,是否是文件。
|
243
|
+
packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
|
244
|
+
|
245
|
+
packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
|
246
|
+
|
247
|
+
puts directoryPath #Dbug.
|
248
|
+
|
249
|
+
#记录时间戳:
|
250
|
+
begin #读取时间戳
|
251
|
+
mtimeStamp=File.mtime(directoryPath) #获取时间戳
|
252
|
+
|
253
|
+
packagedFile['timestamp']={} #时间戳
|
254
|
+
packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
|
255
|
+
packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
|
256
|
+
|
257
|
+
packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
|
258
|
+
rescue Errno::ENOENT
|
259
|
+
rescue Errno::EACCES #权限受限
|
260
|
+
end #begin #读取时间戳
|
261
|
+
|
262
|
+
if (isFile) #是文件,不用再列出其子文件了。
|
263
|
+
packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
|
264
|
+
|
265
|
+
#读取文件内容:
|
266
|
+
fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
267
|
+
currentFileContent=fileToReadContent.read #全部读取
|
268
|
+
@contentPartArray << currentFileContent
|
269
|
+
@bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
|
270
|
+
# @contentString= @contentString + fileToReadContent.read #全部读取。
|
271
|
+
|
272
|
+
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
273
|
+
elsif (isSymLink) #是符号链接
|
274
|
+
linkTarget=directoryPathName.readlink #获取链接目标
|
275
|
+
|
276
|
+
# 待续,设置内容长度。符号链接字符串的长度
|
277
|
+
packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
|
278
|
+
|
279
|
+
#读取文件内容:
|
280
|
+
# fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
281
|
+
currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
282
|
+
@contentPartArray << currentFileContent #加入数组
|
283
|
+
@bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
|
284
|
+
# @contentString= @contentString + StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
285
|
+
|
286
|
+
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
287
|
+
|
288
|
+
else #是目录。
|
289
|
+
# contentString="" #容纳内容的字符串。
|
290
|
+
subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
|
291
|
+
|
292
|
+
packagedFile['file_length']=0 #本目录的内容长度。
|
293
|
+
|
294
|
+
directoryPathName.each_child do |subFile| #一个个文件地处理。
|
295
|
+
# puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
|
296
|
+
# checkMemoryUsage(221)
|
297
|
+
realPath=subFile.expand_path #获取绝对路径。
|
298
|
+
|
299
|
+
packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
|
300
|
+
|
301
|
+
packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
|
302
|
+
|
303
|
+
# puts("sub file content: #{subFileContent}, nil?: #{subFileContent.nil?}" ) #Debug
|
304
|
+
|
305
|
+
# puts(" content: #{contentString}, nil?: #{contentString.nil? }") #Debug
|
306
|
+
|
307
|
+
# contentString = contentString + subFileContent #串接文件内容。
|
308
|
+
|
309
|
+
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
310
|
+
|
311
|
+
|
312
|
+
subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
|
313
|
+
|
314
|
+
# puts("237, content string length: #{contentString.length}") #Debug
|
315
|
+
|
316
|
+
packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
|
317
|
+
end #directoryPathName.each_child do |subFile| #一个个文件地处理。
|
318
|
+
end #if (isFile) #是文件,不用再列出其子文件了。
|
319
|
+
|
320
|
+
# puts("300, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
|
321
|
+
|
322
|
+
|
323
|
+
# puts("302, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
|
324
|
+
|
325
|
+
contentToResult="" #要返回的内容
|
326
|
+
|
327
|
+
if (layer==0) #是最外层
|
328
|
+
assessDiskFlush(layer, true) #考虑是否要向磁盘先输出内容
|
329
|
+
|
330
|
+
if (@diskFlush) #要向磁盘写入缓存内容
|
331
|
+
else #不向磁盘写入缓存内容
|
332
|
+
contentToResult=@contentPartArray.join #重新合并成字符串
|
333
|
+
|
334
|
+
end #if (@diskFlush) #要向磁盘写入缓存内容
|
335
|
+
end #if (layer==0) #是最外层
|
336
|
+
return packagedFile, contentToResult #返回打包之后的对象。和文件内容字节数组。
|
337
|
+
end #def downloadOne #下载一个视频。
|
202
338
|
end
|
203
339
|
|
data/victoriafresh.example.rb
CHANGED
@@ -9,6 +9,11 @@ else #指定了命令行参数。
|
|
9
9
|
|
10
10
|
$clipDownloader=VictoriaFresh.new #创建下载器。
|
11
11
|
|
12
|
+
$clipDownloader.diskFlush=true #向磁盘写入缓存
|
13
|
+
$clipDownloader.diskMultiFile=true #写多个磁盘文件
|
14
|
+
$clipDownloader.diskFileName='victoriafreshdata.v.' #磁盘文件名前缀
|
15
|
+
$clipDownloader.diskFlushSize=32*1024*1024 #磁盘文件大小
|
16
|
+
|
12
17
|
victoriaFresh,victoriaFreshData=$clipDownloader.checkOnce($rootPath) #打包该目录树。
|
13
18
|
|
14
19
|
#利用protobuf打包成字节数组:
|
@@ -22,7 +27,7 @@ else #指定了命令行参数。
|
|
22
27
|
|
23
28
|
victoriaFreshFile.close #关闭文件。
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
# victoriaFreshDataFile=File.new("victoriafreshdata.v","wb") #数据文件。
|
31
|
+
# victoriaFreshDataFile.syswrite(victoriaFreshData) #写入文件。
|
32
|
+
# victoriaFreshDataFile.close #关闭文件。
|
28
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: VictoriaFreSh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2021.4.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hxcan Cai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor
|