summaryrefslogtreecommitdiff
path: root/bilibili
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-09 02:30:19 +0800
committerKeuin <[email protected]>2022-09-09 02:30:41 +0800
commitf028bff042f471a68dff681af9c79ef96bc952e5 (patch)
tree40763feb1d0ec05260e56d6822622462b35b165a /bilibili
parent719946a8211f3c8c68234a7c9e9c5af0226386aa (diff)
Fix file buffer does not take effect. No idea why golang's io utility is so suck. Use ad-hoc buffered copy loop instead.
Diffstat (limited to 'bilibili')
-rw-r--r--bilibili/streaming.go8
1 files changed, 5 insertions, 3 deletions
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