VictoriaFreSh 2021.4.17 → 2021.5.9

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