(fileData wshrpc.FileData, reader io.Reader)
| 49 | } |
| 50 | |
| 51 | func streamWriteToFile(fileData wshrpc.FileData, reader io.Reader) error { |
| 52 | // First truncate the file with an empty write |
| 53 | emptyWrite := fileData |
| 54 | emptyWrite.Data64 = "" |
| 55 | err := wshclient.FileWriteCommand(RpcClient, emptyWrite, &wshrpc.RpcOpts{Timeout: fileTimeout}) |
| 56 | if err != nil { |
| 57 | return fmt.Errorf("initializing file with empty write: %w", err) |
| 58 | } |
| 59 | |
| 60 | const chunkSize = wshrpc.FileChunkSize // 32KB chunks |
| 61 | buf := make([]byte, chunkSize) |
| 62 | totalWritten := int64(0) |
| 63 | |
| 64 | for { |
| 65 | n, err := reader.Read(buf) |
| 66 | if err == io.EOF { |
| 67 | break |
| 68 | } |
| 69 | if err != nil { |
| 70 | return fmt.Errorf("reading input: %w", err) |
| 71 | } |
| 72 | |
| 73 | // Check total size |
| 74 | totalWritten += int64(n) |
| 75 | if totalWritten > MaxFileSize { |
| 76 | return fmt.Errorf("input exceeds maximum file size of %d bytes", MaxFileSize) |
| 77 | } |
| 78 | |
| 79 | // Prepare and send chunk |
| 80 | chunk := buf[:n] |
| 81 | appendData := fileData |
| 82 | appendData.Data64 = base64.StdEncoding.EncodeToString(chunk) |
| 83 | |
| 84 | err = wshclient.FileAppendCommand(RpcClient, appendData, &wshrpc.RpcOpts{Timeout: int64(fileTimeout)}) |
| 85 | if err != nil { |
| 86 | return fmt.Errorf("appending chunk to file: %w", err) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | func streamReadFromFile(ctx context.Context, fileData wshrpc.FileData, writer io.Writer) error { |
| 94 | broker := RpcClient.StreamBroker |
nothing calls this directly
no test coverage detected