Correctly manage partial writes

This commit is contained in:
9seconds
2021-03-29 10:26:52 +03:00
parent db8614999a
commit 3992054560
7 changed files with 75 additions and 38 deletions
+22 -5
View File
@@ -1,16 +1,24 @@
package obfuscated2
import (
"bytes"
"crypto/sha256"
"hash"
"sync"
)
var sha256HasherPool = sync.Pool{
New: func() interface{} {
return sha256.New()
},
}
var (
sha256HasherPool = sync.Pool{
New: func() interface{} {
return sha256.New()
},
}
bytesBufferPool = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
)
func acquireSha256Hasher() hash.Hash {
return sha256HasherPool.Get().(hash.Hash)
@@ -20,3 +28,12 @@ func releaseSha256Hasher(h hash.Hash) {
h.Reset()
sha256HasherPool.Put(h)
}
func acquireBytesBuffer() *bytes.Buffer {
return bytesBufferPool.Get().(*bytes.Buffer)
}
func releaseBytesBuffer(buf *bytes.Buffer) {
buf.Reset()
bytesBufferPool.Put(buf)
}