Pkg: Add fs/README.md to document performance & security improvements

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-11-25 13:09:48 +01:00
parent 897dfe7264
commit 1631aecea6
7 changed files with 294 additions and 28 deletions

24
pkg/fs/buffer_pool.go Normal file
View File

@@ -0,0 +1,24 @@
package fs
import "sync"
// copyBufferSize defines the shared buffer length used for large file copies/hashes.
const copyBufferSize = 256 * 1024
// copyBufferPool reuses byte slices to reduce allocations during file I/O.
var copyBufferPool = sync.Pool{ //nolint:gochecknoglobals // shared pool for I/O buffers
New: func() any {
buf := make([]byte, copyBufferSize)
return &buf
},
}
// getCopyBuffer returns a pooled buffer for copy operations.
func getCopyBuffer() []byte {
return *(copyBufferPool.Get().(*[]byte))
}
// putCopyBuffer returns a buffer to the pool.
func putCopyBuffer(buf []byte) {
copyBufferPool.Put(&buf)
}