VictoriaFreSh 2020.10.31 → 2021.4.17
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 +126 -19
- data/victoriafresh.example.rb +2 -0
- 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: 2c90c85569d4f2c8396f17754e03eb87e35c272b015397983c2afa9af9492ccf
|
4
|
+
data.tar.gz: e88f1ac7afb0ab584ed2973fcceec8701f379c0e5e7f0a22e3be07569799c63c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 130b068d432a0199bab6ab093619e4c0e56f31a5437115138a767e719f62083fe07c45abd6cbb5f90661a99122ffa3a8efea57e815c42ccf007ecf7bc5b64e9a
|
7
|
+
data.tar.gz: 3c25711cbca993d774d5581f507c7087951304fcb3ae5dfb971ce0cfc93f58b7364c28108e56be3976dffd884d9f7d68dbd9290967fe3293954f03e095bca05c
|
data/lib/victoriafresh.rb
CHANGED
@@ -3,10 +3,34 @@
|
|
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
|
+
end
|
25
|
+
|
26
|
+
def checkMemoryUsage(lineNumber)
|
27
|
+
mem= GetProcessMem.new
|
28
|
+
|
29
|
+
puts("#{lineNumber} , Memory: #{mem.mb}"); #Debug
|
30
|
+
|
31
|
+
end #def checkMemoryUsage
|
32
|
+
|
33
|
+
|
10
34
|
def releaseFiles(victoriaFreshPackagedFileString, contentString) #释放目录树
|
11
35
|
# packagedFile=Com::Stupidbeauty::Victoriafresh::FileMessage.decode(victoriaFreshPackagedFileString) #解码文件消息对象。
|
12
36
|
packagedFile=CBOR.decode(victoriaFreshPackagedFileString) #解码
|
@@ -88,8 +112,6 @@ class VictoriaFresh
|
|
88
112
|
|
89
113
|
|
90
114
|
# puts 'mkdir' #Debug
|
91
|
-
|
92
|
-
# pathToMake=File.join(pathPrefix, packagedFile.name)
|
93
115
|
pathToMake=File.join(pathPrefix, packagedFile['name'])
|
94
116
|
|
95
117
|
# puts pathToMake #Debug.
|
@@ -129,7 +151,68 @@ class VictoriaFresh
|
|
129
151
|
end #if packagedFile.is_file #是文件,则直接写入文件
|
130
152
|
end #def releaseFile(packagedFile, contentString) #释放一个文件
|
131
153
|
|
132
|
-
|
154
|
+
#考虑是否要向磁盘先输出内容
|
155
|
+
def assessDiskFlush(layer, isFinalPart=false)
|
156
|
+
# contentString=contentStringInput #要处理的内容字符串
|
157
|
+
|
158
|
+
# if (layer==0) #是最外层
|
159
|
+
while (@contentString.length >= @diskFlushSize) #还有内容要写入
|
160
|
+
contentToWrite=@contentString[0, @diskFlushSize] #取出开头的一段
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
@contentString=@contentString[@diskFlushSize, @contentString.length-@diskFlushSize] #留下剩余的部分
|
165
|
+
|
166
|
+
if (@diskFlush) #要向磁盘写入内容
|
167
|
+
|
168
|
+
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
169
|
+
|
170
|
+
@diskWriteFileObject.flush #写入磁盘
|
171
|
+
|
172
|
+
else #不向磁盘写入内容
|
173
|
+
@contentPartArray << contentToWrite #记录到数组中
|
174
|
+
|
175
|
+
end #if (@diskFlush) #要向磁盘写入内容
|
176
|
+
end #while (contentString.length >= @diskFlushSize) #还有内容要写入
|
177
|
+
|
178
|
+
if (isFinalPart) #是最后一部分
|
179
|
+
contentToWrite=@contentString #要写入的内容
|
180
|
+
|
181
|
+
# @contentPartArray << contentToWrite #记录到数组中
|
182
|
+
|
183
|
+
@contentString="" #字符串清空
|
184
|
+
|
185
|
+
if (@diskFlush) #要向磁盘写入内容
|
186
|
+
|
187
|
+
@diskWriteFileObject.syswrite(contentToWrite) #写入内容
|
188
|
+
|
189
|
+
@diskWriteFileObject.close #关闭文件
|
190
|
+
else #不向磁盘写入内容
|
191
|
+
@contentPartArray << contentToWrite #记录到数组中
|
192
|
+
|
193
|
+
|
194
|
+
end #if (@diskFlush) #要向磁盘写入内容
|
195
|
+
|
196
|
+
end #if (isFinalPart) #是最后一部分
|
197
|
+
# end #if (layer==0) #是最外层
|
198
|
+
|
199
|
+
# end #if (@diskFlush) #要向磁盘写入内容
|
200
|
+
|
201
|
+
return @contentString #返回内容
|
202
|
+
end #contentString= assessDiskFlush(contentString) #考虑是否要向磁盘先输出内容
|
203
|
+
|
204
|
+
def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
|
205
|
+
if (@diskFlush) #要向磁盘写入文件
|
206
|
+
|
207
|
+
if (layer==0) #最外层
|
208
|
+
if (@diskMultiFile) #要写多个文件
|
209
|
+
else #不写多个文件
|
210
|
+
@diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
|
211
|
+
end #if (@diskMultiFile) #要写多个文件
|
212
|
+
end #if (layer==0) #最外层
|
213
|
+
|
214
|
+
end #if (@diskFlush) #要向磁盘写入文件s
|
215
|
+
|
133
216
|
packagedFile={} #创建文件消息对象。
|
134
217
|
|
135
218
|
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
@@ -162,55 +245,79 @@ class VictoriaFresh
|
|
162
245
|
rescue Errno::ENOENT
|
163
246
|
rescue Errno::EACCES #权限受限
|
164
247
|
end #begin #读取时间戳
|
165
|
-
|
248
|
+
|
166
249
|
if (isFile) #是文件,不用再列出其子文件了。
|
167
250
|
packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
|
168
251
|
|
169
252
|
#读取文件内容:
|
170
253
|
fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
171
|
-
contentString=fileToReadContent.read #全部读取。
|
254
|
+
@contentString= @contentString + fileToReadContent.read #全部读取。
|
172
255
|
|
173
|
-
|
256
|
+
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
174
257
|
elsif (isSymLink) #是符号链接
|
175
|
-
# puts("sub file: #{directoryPathName}, class: #{directoryPathName.class}, symlink: #{directoryPathName.symlink?}, expand_path: #{directoryPathName.expand_path}, file?: #{directoryPathName.file?}, read link: #{directoryPathName.readlink}") #Debug.
|
176
|
-
|
177
258
|
linkTarget=directoryPathName.readlink #获取链接目标
|
178
259
|
|
179
260
|
# 待续,设置内容长度。符号链接字符串的长度
|
180
261
|
packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
|
181
|
-
|
262
|
+
|
182
263
|
#读取文件内容:
|
183
264
|
# fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
184
|
-
contentString=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
185
|
-
|
186
|
-
|
187
|
-
|
265
|
+
@contentString= @contentString + StringIO.new(linkTarget.to_s).binmode.read #全部读取。
|
266
|
+
|
267
|
+
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
268
|
+
|
188
269
|
else #是目录。
|
189
|
-
|
270
|
+
# contentString="" #容纳内容的字符串。
|
190
271
|
subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
|
191
272
|
|
192
|
-
# packagedFile.file_length=0 #本目录的内容长度。
|
193
273
|
packagedFile['file_length']=0 #本目录的内容长度。
|
194
274
|
|
195
275
|
directoryPathName.each_child do |subFile| #一个个文件地处理。
|
196
276
|
# puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
|
277
|
+
# checkMemoryUsage(221)
|
197
278
|
realPath=subFile.expand_path #获取绝对路径。
|
198
279
|
|
199
|
-
packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex) #打包这个子文件。
|
280
|
+
packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
|
200
281
|
|
201
282
|
packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
|
202
283
|
|
203
|
-
# puts("sub file content: #{subFileContent}") #Debug
|
284
|
+
# puts("sub file content: #{subFileContent}, nil?: #{subFileContent.nil?}" ) #Debug
|
204
285
|
|
205
|
-
|
286
|
+
# puts(" content: #{contentString}, nil?: #{contentString.nil? }") #Debug
|
287
|
+
|
288
|
+
# contentString = contentString + subFileContent #串接文件内容。
|
289
|
+
|
290
|
+
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
291
|
+
|
206
292
|
|
207
293
|
subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
|
208
294
|
|
295
|
+
# puts("237, content string length: #{contentString.length}") #Debug
|
296
|
+
|
209
297
|
packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
|
210
298
|
end #directoryPathName.each_child do |subFile| #一个个文件地处理。
|
211
299
|
end #if (isFile) #是文件,不用再列出其子文件了。
|
212
300
|
|
213
|
-
|
301
|
+
# puts("300, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
|
302
|
+
|
303
|
+
|
304
|
+
# puts("302, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
|
305
|
+
|
306
|
+
contentToResult="" #要返回的内容
|
307
|
+
|
308
|
+
if (layer==0) #是最外层
|
309
|
+
assessDiskFlush(layer, true) #考虑是否要向磁盘先输出内容
|
310
|
+
|
311
|
+
if (@diskFlush) #要向磁盘写入缓存内容
|
312
|
+
else #不向磁盘写入缓存内容
|
313
|
+
contentToResult=@contentPartArray.join #重新合并成字符串
|
314
|
+
|
315
|
+
end #if (@diskFlush) #要向磁盘写入缓存内容
|
316
|
+
|
317
|
+
end #if (layer==0) #是最外层
|
318
|
+
|
319
|
+
|
320
|
+
return packagedFile, contentToResult #返回打包之后的对象。和文件内容字节数组。
|
214
321
|
end #def downloadOne #下载一个视频。
|
215
322
|
end
|
216
323
|
|
data/victoriafresh.example.rb
CHANGED
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.17
|
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
|