Source File
woff_compression.go
Belonging Package
github.com/pancsta/d2/lib/font
package fontimport ()// Pool compressor workspace, never font inputs or completed WOFF output.// Large custom-font tables must not increase the retained output buffer size.const maxRetainedWoffBuffer = 64 << 10type woffCompression struct {buffer bytes.Bufferwriter *zlib.Writer}var woffCompressionPool = sync.Pool{New: func() any { return new(woffCompression) },}func acquireWoffCompression() *woffCompression {return woffCompressionPool.Get().(*woffCompression)}func releaseWoffCompression( *woffCompression) {resetWoffCompression()woffCompressionPool.Put()}func resetWoffCompression( *woffCompression) {if .buffer.Cap() > maxRetainedWoffBuffer {.buffer = bytes.Buffer{}} else {.buffer.Reset()clear(.buffer.Bytes()[:.buffer.Cap()])}}// compressTable starts an independent zlib stream, retaining only the working buffers.// The returned bytes must be copied before another table or release.func ( *woffCompression) ( []byte) []byte {.buffer.Reset()if .writer == nil {.writer = zlib.NewWriter(&.buffer)} else {.writer.Reset(&.buffer)}.writer.Write().writer.Flush().writer.Close()return .buffer.Bytes()}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |