Benchmark_Ctx_Body_With_Compression() — fiber Function Reference
Architecture documentation for the Benchmark_Ctx_Body_With_Compression() function in ctx_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 06dac01c_7d74_4efb_b6d1_1cb0e98ca948["Benchmark_Ctx_Body_With_Compression()"] 7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"] 06dac01c_7d74_4efb_b6d1_1cb0e98ca948 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026 style 06dac01c_7d74_4efb_b6d1_1cb0e98ca948 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
ctx_test.go lines 1028–1147
func Benchmark_Ctx_Body_With_Compression(b *testing.B) {
encodingErr := errors.New("failed to encoding data")
var (
compressGzip = func(data []byte) ([]byte, error) {
var buf bytes.Buffer
writer := gzip.NewWriter(&buf)
if _, err := writer.Write(data); err != nil {
return nil, encodingErr
}
if err := writer.Flush(); err != nil {
return nil, encodingErr
}
if err := writer.Close(); err != nil {
return nil, encodingErr
}
return buf.Bytes(), nil
}
compressDeflate = func(data []byte) ([]byte, error) {
var buf bytes.Buffer
writer := zlib.NewWriter(&buf)
if _, err := writer.Write(data); err != nil {
return nil, encodingErr
}
if err := writer.Flush(); err != nil {
return nil, encodingErr
}
if err := writer.Close(); err != nil {
return nil, encodingErr
}
return buf.Bytes(), nil
}
)
const input = "john=doe"
compressionTests := []struct {
compressWriter func([]byte) ([]byte, error)
contentEncoding string
expectedBody []byte
}{
{
contentEncoding: "gzip",
compressWriter: compressGzip,
expectedBody: []byte(input),
},
{
contentEncoding: "gzip,invalid",
compressWriter: compressGzip,
expectedBody: []byte(ErrUnsupportedMediaType.Error()),
},
{
contentEncoding: StrDeflate,
compressWriter: compressDeflate,
expectedBody: []byte(input),
},
{
contentEncoding: "gzip,deflate",
compressWriter: func(data []byte) ([]byte, error) {
var (
buf bytes.Buffer
writer interface {
io.WriteCloser
Flush() error
}
err error
)
// deflate
writer = zlib.NewWriter(&buf)
if _, err = writer.Write(data); err != nil {
return nil, encodingErr
}
if err = writer.Flush(); err != nil {
return nil, encodingErr
}
if err = writer.Close(); err != nil {
return nil, encodingErr
}
data = make([]byte, buf.Len())
copy(data, buf.Bytes())
buf.Reset()
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Benchmark_Ctx_Body_With_Compression() do?
Benchmark_Ctx_Body_With_Compression() is a function in the fiber codebase, defined in ctx_test.go.
Where is Benchmark_Ctx_Body_With_Compression() defined?
Benchmark_Ctx_Body_With_Compression() is defined in ctx_test.go at line 1028.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free