VictoriaFreSh 2020.10.24 → 2021.5.6

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: 0742d069cda4361d3f90519ba1cb187d40ecbf08707bae998439a956d4bd6f93
4
- data.tar.gz: 1b37ab4205b6b0f9dbe681cbe3c7e997e1758f7dfb80688c9606a6fcfba08a75
3
+ metadata.gz: 37e81c76bedab62d7f24f3a32a522f7e2b34d89ce5b9674bf5d8d9abd0b633e3
4
+ data.tar.gz: 9cb68fb7da462cded5735b6f5cf545502dd7c6f15d97afe82504634d864ad983
5
5
  SHA512:
6
- metadata.gz: 1da8a95eddc0a0a30e6878fb808a9b5e1d28c4afd3e9a4dc20e198993b30d57f4996dcf486cf471a0f249fc5e2ec6c3ace720363f6a724625e6a286e764a2c97
7
- data.tar.gz: f75aa4b8fd9e05468dcb76e77064229a674b81c081a44093430145573d9d679530103e8947567fabb685ca28c523831b088b09c6a9ce799205d56939358c406d
6
+ metadata.gz: 5a6fb40b33d588ed426b0914a33e01b582749d5e5c75832c55d017be8b07374b13215d7a15c2ae5571c8a1d4d2471c24304ab69144b81bb299fe9121408d5b3a
7
+ data.tar.gz: 0cb6a7e591ca99ea1572888a14b07af0a13a5414147f181d1ee4cf124416d88885d2c912ae9041a0e1f71223a31abfbacd8e870631980855db471a3334a72238
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
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,26 +201,34 @@ 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
- # puts packagedFile.name #Debug
115
- # puts packagedFile['name'] #Debug
116
- # puts("content stirng length: #{contentString.bytesize}") #Debug
117
- # puts packagedFile.timestamp #Debug
118
- puts packagedFile['timestamp'] #Debug
119
-
120
- # if packagedFile.is_file #是文件,则直接写入文件
121
223
  if packagedFile['is_file'] #是文件,则直接写入文件
122
224
  writeFile(pathPrefix, packagedFile, contentString) #写入文件
123
225
  elsif packagedFile['is_symlink'] #是符号链接,则创建符号链接
124
226
  makeSymlink(pathPrefix, packagedFile, contentString) #创建符号链接
125
- # writeFile(pathPrefix, packagedFile, contentString) #写入文件
126
227
  else #是目录,则创建目录,并递归处理
127
228
  makeDirectory(pathPrefix, packagedFile) #创建目录
128
229
 
129
- # direcotryPathPrefix=pathPrefix + '/' + packagedFile.name #构造针对该目录的路径前缀
130
230
  direcotryPathPrefix=pathPrefix + '/' + packagedFile['name'] #构造针对该目录的路径前缀
131
231
 
132
- # subFiles=packagedFile.sub_files #获取子文件列表。
133
232
  subFiles=packagedFile['sub_files'] #获取子文件列表。
134
233
 
135
234
  subFiles.each do |currentSubFile| #一个个子文件地释放
@@ -139,88 +238,187 @@ class VictoriaFresh
139
238
  end #if packagedFile.is_file #是文件,则直接写入文件
140
239
  end #def releaseFile(packagedFile, contentString) #释放一个文件
141
240
 
142
- def checkOnce(directoryPath,startIndex=0) #打包一个目录树。
143
- packagedFile={} #创建文件消息对象。
144
-
145
- packagedFile['sub_files'] = [] #加入到子文件列表中。
146
-
147
- directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
148
-
149
- baseName=directoryPathName.basename.to_s #基本文件名。
150
-
151
- packagedFile['name']=baseName #设置文件名。
152
-
153
- isFile=directoryPathName.file? #是否是文件。
154
- isSymLink=directoryPathName.symlink? #是否是符号链接
155
-
156
- packagedFile['is_file']=isFile #设置属性,是否是文件。
157
- packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
158
-
159
- packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
160
-
161
- puts directoryPath #Dbug.
162
-
163
- #记录时间戳:
164
- begin #读取时间戳
165
- 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 #重组成整个字符串
166
276
 
167
- packagedFile['timestamp']={} #时间戳
168
- packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
169
- packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
170
-
171
- packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
172
- rescue Errno::ENOENT
173
- rescue Errno::EACCES #权限受限
174
- 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) #考虑是否要向磁盘先输出内容
175
303
 
176
- if (isFile) #是文件,不用再列出其子文件了。
177
- packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
178
-
179
- #读取文件内容:
180
- fileToReadContent=File.new(directoryPath,"rb") #创建文件。
181
- contentString=fileToReadContent.read #全部读取。
182
-
183
- # puts("encoding: #{contentString.encoding}") #Debug.
184
- elsif (isSymLink) #是符号链接
185
- # puts("sub file: #{directoryPathName}, class: #{directoryPathName.class}, symlink: #{directoryPathName.symlink?}, expand_path: #{directoryPathName.expand_path}, file?: #{directoryPathName.file?}, read link: #{directoryPathName.readlink}") #Debug.
186
-
187
- linkTarget=directoryPathName.readlink #获取链接目标
188
-
189
- # 待续,设置内容长度。符号链接字符串的长度
190
- packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
191
-
192
- #读取文件内容:
193
- # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
194
- contentString=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
195
- # contentString=linkTarget.to_s.encode('UTF-8') #全部读取。
196
- puts("encoding: #{contentString.encoding}") #Debug.
197
- puts("content string: #{contentString}") #Debug
198
- else #是目录。
199
- contentString="" #容纳内容的字符串。
200
- subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
201
-
202
- # packagedFile.file_length=0 #本目录的内容长度。
203
- packagedFile['file_length']=0 #本目录的内容长度。
204
-
205
- directoryPathName.each_child do |subFile| #一个个文件地处理。
206
- # puts("sub file: #{subFile}, class: #{subFile.class}, symlink: #{subFile.symlink?}, expand_path: #{subFile.expand_path}, file?: #{subFile.file?}") #Debug.
207
- 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
208
313
 
209
- packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex) #打包这个子文件。
314
+ packagedFile={} #创建文件消息对象。
210
315
 
211
- packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
316
+ packagedFile['sub_files'] = [] #加入到子文件列表中。
212
317
 
213
- # puts("sub file content: #{subFileContent}") #Debug
318
+ directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
214
319
 
215
- contentString = contentString + subFileContent #串接文件内容。
320
+ baseName=directoryPathName.basename.to_s #基本文件名。
216
321
 
217
- subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
322
+ packagedFile['name']=baseName #设置文件名。
218
323
 
219
- packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
220
- end #directoryPathName.each_child do |subFile| #一个个文件地处理。
221
- end #if (isFile) #是文件,不用再列出其子文件了。
222
-
223
- return packagedFile,contentString #返回打包之后的对象。和文件内容字节数组。
224
- 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 #下载一个视频。
225
423
  end
226
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.24
4
+ version: 2021.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hxcan Cai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-24 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor