From f028bff042f471a68dff681af9c79ef96bc952e5 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 9 Sep 2022 02:30:19 +0800 Subject: Fix file buffer does not take effect. No idea why golang's io utility is so suck. Use ad-hoc buffered copy loop instead. --- bilibili/streaming.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bilibili/streaming.go') diff --git a/bilibili/streaming.go b/bilibili/streaming.go index e8a6911..64dc26d 100644 --- a/bilibili/streaming.go +++ b/bilibili/streaming.go @@ -5,8 +5,8 @@ import ( "context" "errors" "fmt" - "io" "net/http" + "os" "strings" ) @@ -15,7 +15,9 @@ func (b Bilibili) CopyLiveStream( ctx context.Context, roomId common.RoomId, stream StreamingUrlInfo, - out io.Writer, + out *os.File, + buffer []byte, + readChunkSize int, ) (err error) { url := stream.URL if !strings.HasPrefix(url, "https://") && @@ -60,7 +62,7 @@ func (b Bilibili) CopyLiveStream( defer cancelGuardian() // blocking copy - n, err := common.Copy(ctx, out, resp.Body) + n, err := common.CopyToFileWithBuffer(ctx, out, resp.Body, buffer, readChunkSize, false) if err != nil && !errors.Is(err, context.Canceled) { // real error happens -- cgit v1.2.3