MCPcopy
hub / github.com/rclone/rclone / OpenChunkWriter

Method OpenChunkWriter

backend/oracleobjectstorage/multipart.go:66–127  ·  view source on GitHub ↗

OpenChunkWriter returns the chunk size and a ChunkWriter Pass in the remote and the src object You can also use options to hint at the desired chunk size

(
	ctx context.Context,
	remote string,
	src fs.ObjectInfo,
	options ...fs.OpenOption)

Source from the content-addressed store, hash-verified

64// Pass in the remote and the src object
65// You can also use options to hint at the desired chunk size
66func (f *Fs) OpenChunkWriter(
67 ctx context.Context,
68 remote string,
69 src fs.ObjectInfo,
70 options ...fs.OpenOption) (info fs.ChunkWriterInfo, writer fs.ChunkWriter, err error) {
71 // Temporary Object under construction
72 o := &Object{
73 fs: f,
74 remote: remote,
75 }
76 ui, err := o.prepareUpload(ctx, src, options)
77 if err != nil {
78 return info, nil, fmt.Errorf("failed to prepare upload: %w", err)
79 }
80
81 uploadParts := f.opt.MaxUploadParts
82 if uploadParts < 1 {
83 uploadParts = 1
84 } else if uploadParts > maxUploadParts {
85 uploadParts = maxUploadParts
86 }
87 size := src.Size()
88
89 // calculate size of parts
90 chunkSize := f.opt.ChunkSize
91
92 // size can be -1 here meaning we don't know the size of the incoming file. We use ChunkSize
93 // buffers here (default 5 MiB). With a maximum number of parts (10,000) this will be a file of
94 // 48 GiB which seems like a not too unreasonable limit.
95 if size == -1 {
96 warnStreamUpload.Do(func() {
97 fs.Logf(f, "Streaming uploads using chunk size %v will have maximum file size of %v",
98 f.opt.ChunkSize, fs.SizeSuffix(int64(chunkSize)*int64(uploadParts)))
99 })
100 } else {
101 chunkSize = chunksize.Calculator(src, size, uploadParts, chunkSize)
102 }
103
104 uploadID, existingParts, err := o.createMultipartUpload(ctx, ui.req)
105 if err != nil {
106 return info, nil, fmt.Errorf("create multipart upload request failed: %w", err)
107 }
108 bucketName, bucketPath := o.split()
109 chunkWriter := &objectChunkWriter{
110 chunkSize: int64(chunkSize),
111 size: size,
112 f: f,
113 bucket: &bucketName,
114 key: &bucketPath,
115 uploadID: &uploadID,
116 existingParts: existingParts,
117 ui: ui,
118 o: o,
119 }
120 info = fs.ChunkWriterInfo{
121 ChunkSize: int64(chunkSize),
122 Concurrency: o.fs.opt.UploadConcurrency,
123 LeavePartsOnError: o.fs.opt.LeavePartsOnError,

Callers

nothing calls this directly

Calls 10

prepareUploadMethod · 0.95
createMultipartUploadMethod · 0.95
splitMethod · 0.95
LogfFunction · 0.92
SizeSuffixTypeAlias · 0.92
CalculatorFunction · 0.92
DebugfFunction · 0.92
SizeMethod · 0.65
DoMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected