mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	在写入缓存数据时自动分多次写入“大”的文件内容
This commit is contained in:
		@@ -75,23 +75,30 @@ func (this *FileWriter) WriteHeaderLength(headerLength int) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Write 写入数据
 | 
					// Write 写入数据
 | 
				
			||||||
func (this *FileWriter) Write(data []byte) (n int, err error) {
 | 
					func (this *FileWriter) Write(data []byte) (n int, err error) {
 | 
				
			||||||
	fsutils.WriteBegin()
 | 
						// split LARGE data
 | 
				
			||||||
	n, err = this.rawWriter.Write(data)
 | 
						var l = len(data)
 | 
				
			||||||
	fsutils.WriteEnd()
 | 
						if l > (2 << 20) {
 | 
				
			||||||
	this.bodySize += int64(n)
 | 
							var offset = 0
 | 
				
			||||||
 | 
							const bufferSize = 256 << 10
 | 
				
			||||||
	if this.maxSize > 0 && this.bodySize > this.maxSize {
 | 
							for {
 | 
				
			||||||
		err = ErrEntityTooLarge
 | 
								var end = offset + bufferSize
 | 
				
			||||||
 | 
								if end > l {
 | 
				
			||||||
		if this.storage != nil {
 | 
									end = l
 | 
				
			||||||
			this.storage.IgnoreKey(this.key, this.maxSize)
 | 
								}
 | 
				
			||||||
 | 
								n1, err1 := this.write(data[offset:end])
 | 
				
			||||||
 | 
								n += n1
 | 
				
			||||||
 | 
								if err1 != nil {
 | 
				
			||||||
 | 
									return n, err1
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if end >= l {
 | 
				
			||||||
 | 
									return n, nil
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								offset = end
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						// write NORMAL size data
 | 
				
			||||||
		_ = this.Discard()
 | 
						return this.write(data)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// WriteAt 在指定位置写入数据
 | 
					// WriteAt 在指定位置写入数据
 | 
				
			||||||
@@ -187,3 +194,23 @@ func (this *FileWriter) Key() string {
 | 
				
			|||||||
func (this *FileWriter) ItemType() ItemType {
 | 
					func (this *FileWriter) ItemType() ItemType {
 | 
				
			||||||
	return ItemTypeFile
 | 
						return ItemTypeFile
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (this *FileWriter) write(data []byte) (n int, err error) {
 | 
				
			||||||
 | 
						fsutils.WriteBegin()
 | 
				
			||||||
 | 
						n, err = this.rawWriter.Write(data)
 | 
				
			||||||
 | 
						fsutils.WriteEnd()
 | 
				
			||||||
 | 
						this.bodySize += int64(n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if this.maxSize > 0 && this.bodySize > this.maxSize {
 | 
				
			||||||
 | 
							err = ErrEntityTooLarge
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if this.storage != nil {
 | 
				
			||||||
 | 
								this.storage.IgnoreKey(this.key, this.maxSize)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							_ = this.Discard()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user