VictoriaFreSh 2020.10.31 → 2021.5.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e3f7b0d2274b3e4d1053b1ea06d25d0136a9d4cf877a76dd802c4ea89d0b1b7
4
- data.tar.gz: c3723184467e8e953fcd01cacb7c02a7cc1c77a43f1cf7bfe47b81ad41d8ca3e
3
+ metadata.gz: 2ab9ba367bf11f6d810dd1981a9169ce6110516d6fbbfd687cf33197d3e88151
4
+ data.tar.gz: 19f5fc0336f9ecf2ecccb1f84cc2d0426467fed64118936212d1534ffdbf52a0
5
5
  SHA512:
6
- metadata.gz: 27ffe0e19351ed1e013465dde4cf4c1adbe16ccef807319feea079880c7f0827bc460ec6e5f6d8d90c261189796e9aae48ab9cd4c9bfc033c79c0b774640480c
7
- data.tar.gz: b03f697db6128b7d582d3c491c67d0c3950d7a8937b8562e5e1510170ba41d5115017aedee13eeaa574ef50d3e49558864cb87f6d4cae87138f824da472dc71b
6
+ metadata.gz: 79e176c193558179379d99a0c3d15b189054e99810a8a7238439d609765e15a86504ca869b14516e9cd38b66abdda3cdde29077b4ade0d87f2300ba9c97626b3
7
+ data.tar.gz: 936fff34a3f634cc03c5000ff94a2691b8797561d367e53dddf0484d8a58bd8ed6bf4d4419cbcbcd0602ebb8410e86c186555cdd0dcda58081c2e068d2d92304
data/lib/victoriafresh.rb CHANGED
@@ -3,20 +3,85 @@
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
+ attr_accessor :currentDiskFlushSuffix #当前的文件后缀。也等价于已经写入的文件片段个数
16
+
17
+ def initialize
18
+ @diskFlush=false #要向磁盘写入文件
19
+ @diskFlushSize=143212 #磁盘分块大小
20
+ @diskFileName='victoriafreshdata.v' #磁盘文件名
21
+ @diskMultiFile=false #磁盘整个文件,不是多个文件
22
+ @diskWriteFileObject={} #向磁盘写入文件的对象
23
+ @contentString="" #内容字符串
24
+ @contentPartArray=[] #内容片段数组
25
+ @currentDiskFlushSuffix=0 #当前的磁盘文件后缀
26
+ @bufferLength=0 #缓冲区总长度
27
+ @externalDataFile={} #外部数据文件对象
28
+ end
29
+
30
+ def checkMemoryUsage(lineNumber)
31
+ mem= GetProcessMem.new
32
+
33
+ puts("#{lineNumber} , Memory: #{mem.mb}"); #Debug
34
+
35
+ end #def checkMemoryUsage
36
+
10
37
  def releaseFiles(victoriaFreshPackagedFileString, contentString) #释放目录树
11
- # packagedFile=Com::Stupidbeauty::Victoriafresh::FileMessage.decode(victoriaFreshPackagedFileString) #解码文件消息对象。
12
38
  packagedFile=CBOR.decode(victoriaFreshPackagedFileString) #解码
13
-
14
39
 
15
- puts packagedFile #Debug
40
+ # puts packagedFile #Debug
16
41
 
17
42
  releaseFile('.', packagedFile, contentString) #释放一个文件
18
43
  end #def releaseFiles(victoriaFreshPackagedFile, contentString) #释放目录树
19
44
 
45
+ def releaseFilesExternalDataFile(victoriaFreshPackagedFileString, externalDataFileName) #释放目录树
46
+ packagedFile=CBOR.decode(victoriaFreshPackagedFileString) #解码
47
+
48
+ # puts packagedFile #Debug
49
+
50
+ @externalDataFile=File.open(externalDataFileName, 'rb') #打开文件
51
+
52
+ releaseFileExternalDataFile('.', packagedFile) #释放一个文件
53
+
54
+ @externalDataFile.close #关闭文件
55
+ end #def releaseFiles(victoriaFreshPackagedFile, contentString) #释放目录树
56
+
57
+ def writeFileExternalDataFile(pathPrefix, packagedFile) #写入文件
58
+ timeObject=getTimeObject(packagedFile) #构造时间戳对象
59
+
60
+ @externalDataFile.seek(packagedFile['file_start_index']) #定位到起始位置
61
+
62
+ victoriaFreshData=@externalDataFile.read(packagedFile['file_length']) #读取内容
63
+
64
+ # victoriaFreshData=contentString[packagedFile.file_start_index, packagedFile.file_length] #获取内容
65
+ # victoriaFreshData=contentString[ packagedFile['file_start_index'], packagedFile['file_length'] ] #获取内容
66
+
67
+ # pathToMake=pathPrefix + '/' + packagedFile.name #构造文件名
68
+ pathToMake=pathPrefix + '/' + packagedFile['name'] #构造文件名
69
+
70
+ victoriaFreshDataFile=File.new(pathToMake , "wb", packagedFile['permission']) #数据文件。
71
+ victoriaFreshDataFile.syswrite(victoriaFreshData) #写入文件。
72
+ victoriaFreshDataFile.close #关闭文件。
73
+
74
+ FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
75
+
76
+ permissionNumber=packagedFile['permission'] #获取权限数字
77
+
78
+ if (permissionNumber.nil?) #不带权限字段
79
+ elsif #带权限字段
80
+ File.chmod(permissionNumber, pathToMake) #设置权限
81
+ end #if (permissionNumber.nil?) #不带权限字段
82
+
83
+ end #def writeFileExternalDataFile(pathPrefix, packagedFile) #写入文件
84
+
20
85
  def writeFile(pathPrefix, packagedFile, contentString) #写入文件
21
86
 
22
87
  timeObject=getTimeObject(packagedFile) #构造时间戳对象
@@ -39,9 +104,37 @@ class VictoriaFresh
39
104
  elsif #带权限字段
40
105
  File.chmod(permissionNumber, pathToMake) #设置权限
41
106
  end #if (permissionNumber.nil?) #不带权限字段
42
-
107
+
43
108
  end #writeFile(pathPrefix, packagedFile, contentString) #写入文件
44
109
 
110
+ #创建符号链接
111
+ def makeSymlinkExternalDataFile(pathPrefix, packagedFile)
112
+ puts("start index: #{packagedFile['file_start_index']}, length: #{packagedFile['file_length']}, content string length: #{contentString.bytesize}") #Debug
113
+
114
+ @externalDataFile.seek(packagedFile['file_start_index']) #定位到起始位置
115
+
116
+ victoriaFreshData=@externalDataFile.read(packagedFile['file_length']) #读取内容
117
+ # victoriaFreshData=contentString[ packagedFile['file_start_index'], packagedFile['file_length'] ] #获取内容
118
+
119
+ pathToMake=pathPrefix + '/' + packagedFile['name'] #构造文件名
120
+
121
+ puts("data: #{victoriaFreshData}, path: #{pathToMake}") #Debug
122
+
123
+ FileUtils.symlink(victoriaFreshData, pathToMake, force: true) #创建符号链接
124
+
125
+ permissionNumber=packagedFile['permission'] #获取权限数字
126
+
127
+ if (permissionNumber.nil?) #不带权限字段
128
+ elsif #带权限字段
129
+ # File.chmod(permissionNumber, pathToMake) #设置权限
130
+ begin #尝试修改链接本身的权限
131
+ File.lchmod(permissionNumber, pathToMake) #设置权限
132
+ rescue NotImplementedError #未实现
133
+ puts 'File.lchmod not implemented' #Debug
134
+ end #begin #尝试修改链接本身的权限
135
+ end #if (permissionNumber.nil?) #不带权限字段
136
+ end #def makeSymlinkExternalDataFile(pathPrefix, packagedFile)
137
+
45
138
  #创建符号链接
46
139
  def makeSymlink(pathPrefix, packagedFile, contentString)
47
140
  puts("start index: #{packagedFile['file_start_index']}, length: #{packagedFile['file_length']}, content string length: #{contentString.bytesize}") #Debug
@@ -49,12 +142,12 @@ class VictoriaFresh
49
142
 
50
143
  pathToMake=pathPrefix + '/' + packagedFile['name'] #构造文件名
51
144
 
52
- # victoriaFreshDataFile=File.new(pathToMake , "wb") #数据文件。
53
- # victoriaFreshDataFile.syswrite(victoriaFreshData) #写入文件。
54
- # victoriaFreshDataFile.close #关闭文件。
55
- #
56
- # FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
57
-
145
+ # victoriaFreshDataFile=File.new(pathToMake , "wb") #数据文件。
146
+ # victoriaFreshDataFile.syswrite(victoriaFreshData) #写入文件。
147
+ # victoriaFreshDataFile.close #关闭文件。
148
+ #
149
+ # FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
150
+
58
151
  puts("data: #{victoriaFreshData}, path: #{pathToMake}") #Debug
59
152
 
60
153
  FileUtils.symlink(victoriaFreshData, pathToMake, force: true) #创建符号链接
@@ -63,7 +156,7 @@ class VictoriaFresh
63
156
 
64
157
  if (permissionNumber.nil?) #不带权限字段
65
158
  elsif #带权限字段
66
- # File.chmod(permissionNumber, pathToMake) #设置权限
159
+ # File.chmod(permissionNumber, pathToMake) #设置权限
67
160
  begin #尝试修改链接本身的权限
68
161
  File.lchmod(permissionNumber, pathToMake) #设置权限
69
162
  rescue NotImplementedError #未实现
@@ -73,33 +166,31 @@ class VictoriaFresh
73
166
  end #def makeSymlink(pathPrefix, packagedFile, contentString) #创建符号链接
74
167
 
75
168
  def getTimeObject(packagedFile) #构造时间戳对象
76
- # seconds=packagedFile.timestamp.seconds #获取秒数
169
+ # seconds=packagedFile.timestamp.seconds #获取秒数
77
170
  seconds=packagedFile['timestamp']['seconds'] #获取秒数
78
-
79
- # microSeconds=packagedFile.timestamp.nanos/ 1000.0 #获取毫秒数
171
+
172
+ # microSeconds=packagedFile.timestamp.nanos/ 1000.0 #获取毫秒数
80
173
  microSeconds=packagedFile['timestamp']['nanos'] / 1000.0 #获取毫秒数
81
174
 
82
175
  timeObject=Time.at(seconds, microSeconds) #构造时间对象
83
-
176
+
84
177
  end #getTimeObject(packagedFile) #构造时间戳对象
85
178
 
86
179
  def makeDirectory(pathPrefix, packagedFile) #创建目录
87
180
  timeObject=getTimeObject(packagedFile) #构造时间戳对象
88
-
89
181
 
90
- # puts 'mkdir' #Debug
91
182
 
92
- # pathToMake=File.join(pathPrefix, packagedFile.name)
183
+ # puts 'mkdir' #Debug
93
184
  pathToMake=File.join(pathPrefix, packagedFile['name'])
94
185
 
95
- # puts pathToMake #Debug.
186
+ # puts pathToMake #Debug.
96
187
 
97
188
  if (Dir.exist?(pathToMake)) #目录已经存在
98
189
  else #目录 不存在
99
190
  Dir.mkdir(pathToMake) #=> 0
100
191
  end #if (Dir.exist?(pathToMake)) #目录已经存在
101
192
 
102
-
193
+
103
194
  FileUtils.touch pathToMake, :mtime => timeObject #设置修改时间
104
195
 
105
196
  permissionNumber=packagedFile['permission'] #获取权限数字
@@ -110,6 +201,24 @@ class VictoriaFresh
110
201
  end #if (permissionNumber.nil?) #不带权限字段
111
202
  end #makeDirectory(pathPrefix, packagedFile) #创建目录
112
203
 
204
+ def releaseFileExternalDataFile(pathPrefix, packagedFile) #释放一个文件
205
+ if packagedFile['is_file'] #是文件,则直接写入文件
206
+ writeFileExternalDataFile(pathPrefix, packagedFile) #写入文件
207
+ elsif packagedFile['is_symlink'] #是符号链接,则创建符号链接
208
+ makeSymlinkExternalDataFile(pathPrefix, packagedFile) #创建符号链接
209
+ else #是目录,则创建目录,并递归处理
210
+ makeDirectory(pathPrefix, packagedFile) #创建目录
211
+
212
+ direcotryPathPrefix=pathPrefix + '/' + packagedFile['name'] #构造针对该目录的路径前缀
213
+
214
+ subFiles=packagedFile['sub_files'] #获取子文件列表。
215
+
216
+ subFiles.each do |currentSubFile| #一个个子文件地释放
217
+ releaseFileExternalDataFile(direcotryPathPrefix, currentSubFile) #释放子文件
218
+ end #subFiles.each do |currentSubFile| #一个个子文件地释放
219
+ end #if packagedFile.is_file #是文件,则直接写入文件
220
+ end #def releaseFileExternalDataFile(pathPrefix, packagedFile) #释放一个文件
221
+
113
222
  def releaseFile( pathPrefix, packagedFile, contentString) #释放一个文件
114
223
  if packagedFile['is_file'] #是文件,则直接写入文件
115
224
  writeFile(pathPrefix, packagedFile, contentString) #写入文件
@@ -129,88 +238,187 @@ class VictoriaFresh
129
238
  end #if packagedFile.is_file #是文件,则直接写入文件
130
239
  end #def releaseFile(packagedFile, contentString) #释放一个文件
131
240
 
132
- def checkOnce(directoryPath,startIndex=0) #打包一个目录树。
133
- packagedFile={} #创建文件消息对象。
134
-
135
- packagedFile['sub_files'] = [] #加入到子文件列表中。
136
-
137
- directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
138
-
139
- baseName=directoryPathName.basename.to_s #基本文件名。
140
-
141
- packagedFile['name']=baseName #设置文件名。
142
-
143
- isFile=directoryPathName.file? #是否是文件。
144
- isSymLink=directoryPathName.symlink? #是否是符号链接
145
-
146
- packagedFile['is_file']=isFile #设置属性,是否是文件。
147
- packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
148
-
149
- packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
150
-
151
- puts directoryPath #Dbug.
152
-
153
- #记录时间戳:
154
- begin #读取时间戳
155
- mtimeStamp=File.mtime(directoryPath) #获取时间戳
241
+ #考虑是否要向磁盘先输出内容
242
+ def assessDiskFlush(layer, isFinalPart=false)
243
+ if (@diskFlush) #要做磁盘写入
244
+ if (@bufferLength>=@diskFlushSize) #缓冲区总长度已经超过需要的文件长度
245
+ @contentString = @contentPartArray.join #重组成整个字符串
246
+
247
+ @contentPartArray.clear #清空数组
248
+
249
+ while (@contentString.length >= @diskFlushSize) #还有内容要写入
250
+ contentToWrite=@contentString[0, @diskFlushSize] #取出开头的一段
251
+
252
+ @contentString=@contentString[@diskFlushSize, @contentString.length-@diskFlushSize] #留下剩余的部分
253
+
254
+ if (@diskMultiFile) #多个磁盘文件
255
+ @diskWriteFileObject=File.new(@diskFileName+@currentDiskFlushSuffix.to_s, 'wb') #打开文件
256
+
257
+ @currentDiskFlushSuffix=@currentDiskFlushSuffix+1 #增加计数
258
+
259
+ @diskWriteFileObject.syswrite(contentToWrite) #写入内容
260
+
261
+ @diskWriteFileObject.close
262
+ else #单个磁盘文件
263
+
264
+ @diskWriteFileObject.syswrite(contentToWrite) #写入内容
265
+
266
+ @diskWriteFileObject.flush #写入磁盘
267
+ end #@currentDiskFlushSuffix
268
+ end #while (contentString.length >= @diskFlushSize) #还有内容要写入
269
+
270
+ @contentPartArray << @contentString #剩余部分重新加入数组中
271
+ @bufferLength=@contentString.length #重新记录缓冲区总长度
272
+ end #if (bufferLength>=@diskFlushSize) #缓冲区总长度已经超过需要的文件长度
273
+
274
+ if (isFinalPart) #是最后一部分
275
+ @contentString = @contentPartArray.join #重组成整个字符串
156
276
 
157
- packagedFile['timestamp']={} #时间戳
158
- packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
159
- packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
160
-
161
- packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
162
- rescue Errno::ENOENT
163
- rescue Errno::EACCES #权限受限
164
- end #begin #读取时间戳
277
+ @contentPartArray.clear #清空字符串数组
278
+ @bufferLength=0 #缓冲区长度归零
279
+
280
+ contentToWrite=@contentString #要写入的内容
281
+
282
+ @contentString="" #字符串清空
283
+
284
+ if (@diskMultiFile) #多个磁盘文件
285
+ @diskWriteFileObject=File.new(@diskFileName+@currentDiskFlushSuffix.to_s, 'wb') #打开文件
286
+
287
+ @currentDiskFlushSuffix=@currentDiskFlushSuffix+1 #增加计数
288
+
289
+ @diskWriteFileObject.syswrite(contentToWrite) #写入内容
290
+
291
+ @diskWriteFileObject.close
292
+
293
+
294
+ else #单个磁盘文件
295
+ @diskWriteFileObject.syswrite(contentToWrite) #写入内容
296
+
297
+ @diskWriteFileObject.close #关闭文件
298
+
299
+ end #if (@diskMultiFile) #多个磁盘文件
300
+ end #if (isFinalPart) #是最后一部分
301
+ end #if (@diskFlush) #要做磁盘写入
302
+ end #contentString= assessDiskFlush(contentString) #考虑是否要向磁盘先输出内容
165
303
 
166
- if (isFile) #是文件,不用再列出其子文件了。
167
- packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
168
-
169
- #读取文件内容:
170
- fileToReadContent=File.new(directoryPath,"rb") #创建文件。
171
- contentString=fileToReadContent.read #全部读取。
172
-
173
- # puts("encoding: #{contentString.encoding}") #Debug.
174
- 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
- linkTarget=directoryPathName.readlink #获取链接目标
178
-
179
- # 待续,设置内容长度。符号链接字符串的长度
180
- packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
181
-
182
- #读取文件内容:
183
- # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
184
- contentString=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
185
- # contentString=linkTarget.to_s.encode('UTF-8') #全部读取。
186
- puts("encoding: #{contentString.encoding}") #Debug.
187
- puts("content string: #{contentString}") #Debug
188
- else #是目录。
189
- contentString="" #容纳内容的字符串。
190
- subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
191
-
192
- # packagedFile.file_length=0 #本目录的内容长度。
193
- packagedFile['file_length']=0 #本目录的内容长度。
194
-
195
- directoryPathName.each_child do |subFile| #一个个文件地处理。
196
- # puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
197
- realPath=subFile.expand_path #获取绝对路径。
304
+ def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
305
+ if (@diskFlush) #要向磁盘写入文件
306
+ if (layer==0) #最外层
307
+ if (@diskMultiFile) #要写多个文件
308
+ else #不写多个文件
309
+ @diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
310
+ end #if (@diskMultiFile) #要写多个文件
311
+ end #if (layer==0) #最外层
312
+ end #if (@diskFlush) #要向磁盘写入文件s
198
313
 
199
- packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex) #打包这个子文件。
314
+ packagedFile={} #创建文件消息对象。
200
315
 
201
- packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
316
+ packagedFile['sub_files'] = [] #加入到子文件列表中。
202
317
 
203
- # puts("sub file content: #{subFileContent}") #Debug
318
+ directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
204
319
 
205
- contentString = contentString + subFileContent #串接文件内容。
320
+ baseName=directoryPathName.basename.to_s #基本文件名。
206
321
 
207
- subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
322
+ packagedFile['name']=baseName #设置文件名。
208
323
 
209
- packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
210
- end #directoryPathName.each_child do |subFile| #一个个文件地处理。
211
- end #if (isFile) #是文件,不用再列出其子文件了。
212
-
213
- return packagedFile,contentString #返回打包之后的对象。和文件内容字节数组。
214
- end #def downloadOne #下载一个视频。
324
+ isFile=directoryPathName.file? #是否是文件。
325
+ isSymLink=directoryPathName.symlink? #是否是符号链接
326
+
327
+ packagedFile['is_file']=isFile #设置属性,是否是文件。
328
+ packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
329
+
330
+ packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
331
+
332
+ puts directoryPath #Dbug.
333
+
334
+ #记录时间戳:
335
+ begin #读取时间戳
336
+ mtimeStamp=File.mtime(directoryPath) #获取时间戳
337
+
338
+ packagedFile['timestamp']={} #时间戳
339
+ packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
340
+ packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
341
+
342
+ packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
343
+ rescue Errno::ENOENT
344
+ rescue Errno::EACCES #权限受限
345
+ end #begin #读取时间戳
346
+
347
+ if (isFile) #是文件,不用再列出其子文件了。
348
+ packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
349
+
350
+ #读取文件内容:
351
+ fileToReadContent=File.new(directoryPath,"rb") #创建文件。
352
+ currentFileContent=fileToReadContent.read #全部读取
353
+ @contentPartArray << currentFileContent
354
+ @bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
355
+ # @contentString= @contentString + fileToReadContent.read #全部读取。
356
+
357
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
358
+ elsif (isSymLink) #是符号链接
359
+ linkTarget=directoryPathName.readlink #获取链接目标
360
+
361
+ # 待续,设置内容长度。符号链接字符串的长度
362
+ packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
363
+
364
+ #读取文件内容:
365
+ # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
366
+ currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
367
+ @contentPartArray << currentFileContent #加入数组
368
+ @bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
369
+ # @contentString= @contentString + StringIO.new(linkTarget.to_s).binmode.read #全部读取。
370
+
371
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
372
+
373
+ else #是目录。
374
+ # contentString="" #容纳内容的字符串。
375
+ subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
376
+
377
+ packagedFile['file_length']=0 #本目录的内容长度。
378
+
379
+ directoryPathName.each_child do |subFile| #一个个文件地处理。
380
+ # puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
381
+ # checkMemoryUsage(221)
382
+ realPath=subFile.expand_path #获取绝对路径。
383
+
384
+ packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
385
+
386
+ packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
387
+
388
+ # puts("sub file content: #{subFileContent}, nil?: #{subFileContent.nil?}" ) #Debug
389
+
390
+ # puts(" content: #{contentString}, nil?: #{contentString.nil? }") #Debug
391
+
392
+ # contentString = contentString + subFileContent #串接文件内容。
393
+
394
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
395
+
396
+
397
+ subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
398
+
399
+ # puts("237, content string length: #{contentString.length}") #Debug
400
+
401
+ packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
402
+ end #directoryPathName.each_child do |subFile| #一个个文件地处理。
403
+ end #if (isFile) #是文件,不用再列出其子文件了。
404
+
405
+ # puts("300, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
406
+
407
+
408
+ # puts("302, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
409
+
410
+ contentToResult="" #要返回的内容
411
+
412
+ if (layer==0) #是最外层
413
+ assessDiskFlush(layer, true) #考虑是否要向磁盘先输出内容
414
+
415
+ if (@diskFlush) #要向磁盘写入缓存内容
416
+ else #不向磁盘写入缓存内容
417
+ contentToResult=@contentPartArray.join #重新合并成字符串
418
+
419
+ end #if (@diskFlush) #要向磁盘写入缓存内容
420
+ end #if (layer==0) #是最外层
421
+ return packagedFile, contentToResult #返回打包之后的对象。和文件内容字节数组。
422
+ end #def downloadOne #下载一个视频。
215
423
  end
216
424
 
@@ -9,6 +9,11 @@ else #指定了命令行参数。
9
9
 
10
10
  $clipDownloader=VictoriaFresh.new #创建下载器。
11
11
 
12
+ $clipDownloader.diskFlush=false #不向磁盘写入缓存
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打包成字节数组:
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: 2020.10.31
4
+ version: 2021.5.8
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: 2020-10-31 00:00:00.000000000 Z
11
+ date: 2021-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.5.9.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: get_process_mem
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.2.7
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.7
33
47
  description: Virtual file system.
34
48
  email: caihuosheng@gmail.com
35
49
  executables: []
@@ -43,7 +57,7 @@ homepage: http://rubygems.org/gems/VictoriaFreSh
43
57
  licenses:
44
58
  - MIT
45
59
  metadata: {}
46
- post_install_message:
60
+ post_install_message:
47
61
  rdoc_options: []
48
62
  require_paths:
49
63
  - lib
@@ -58,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
72
  - !ruby/object:Gem::Version
59
73
  version: '0'
60
74
  requirements: []
61
- rubygems_version: 3.0.3
62
- signing_key:
75
+ rubygems_version: 3.2.15
76
+ signing_key:
63
77
  specification_version: 4
64
78
  summary: VictoriaFreSh
65
79
  test_files: []