-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
airuike
committed
Apr 11, 2020
1 parent
c1e19a7
commit 16e8e12
Showing
7 changed files
with
79 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package lzfse | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
type cachedWriter struct { | ||
w io.Writer | ||
buf []byte | ||
} | ||
|
||
func newCachedWriter(w io.Writer) *cachedWriter { | ||
return &cachedWriter{ | ||
w: w, | ||
buf: make([]byte, 0, 1024), | ||
} | ||
} | ||
|
||
func (cw *cachedWriter) Write(b []byte) (int, error) { | ||
n, err := cw.w.Write(b) | ||
if n > 0 { | ||
cw.buf = append(cw.buf, b[:n]...) | ||
} | ||
return n, err | ||
} | ||
|
||
func (cw *cachedWriter) ReadRelativeToEnd(b []byte, offset int64) (copied int, err error) { | ||
copied = copy(b, cw.buf[int64(len(cw.buf))-offset:]) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters