-
Notifications
You must be signed in to change notification settings - Fork 2
/
bodyReader.go
29 lines (23 loc) · 763 Bytes
/
bodyReader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package compress
import "io"
/*
gin-compress Copyright (C) 2022 Aurora McGinnis
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
// compressedBodyReader wraps the decompressors so that they all are properly closed
type compressedBodyReader struct {
decomps []io.ReadCloser // must be ordered such that the last item in the slice is the last reader
}
func (c *compressedBodyReader) Read(b []byte) (int, error) {
return c.decomps[len(c.decomps)-1].Read(b)
}
func (c *compressedBodyReader) Close() error {
for _, dc := range c.decomps {
if err := dc.Close(); err != nil {
return err
}
}
return nil
}