MCPcopy
hub / github.com/OpenListTeam/OpenList / Put

Method Put

drivers/mega/driver.go:160–196  ·  view source on GitHub ↗
(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress)

Source from the content-addressed store, hash-verified

158}
159
160func (d *Mega) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
161 if dstNode, ok := dstDir.(*MegaNode); ok {
162 u, err := d.c.NewUpload(dstNode.n, stream.GetName(), stream.GetSize())
163 if err != nil {
164 return err
165 }
166
167 reader := driver.NewLimitedUploadStream(ctx, stream)
168 for id := 0; id < u.Chunks(); id++ {
169 if utils.IsCanceled(ctx) {
170 return ctx.Err()
171 }
172 _, chkSize, err := u.ChunkLocation(id)
173 if err != nil {
174 return err
175 }
176 chunk := make([]byte, chkSize)
177 n, err := io.ReadFull(reader, chunk)
178 if err != nil && err != io.EOF {
179 return err
180 }
181 if n != len(chunk) {
182 return errors.New("chunk too short")
183 }
184
185 err = u.UploadChunk(id, chunk)
186 if err != nil {
187 return err
188 }
189 up(float64(id) * 100 / float64(u.Chunks()))
190 }
191
192 _, err = u.Finish()
193 return err
194 }
195 return fmt.Errorf("unable to convert dir to mega n")
196}
197
198func (d *Mega) GetDetails(ctx context.Context) (*model.StorageDetails, error) {
199 quota, err := d.c.GetQuota()

Callers

nothing calls this directly

Calls 7

NewLimitedUploadStreamFunction · 0.92
IsCanceledFunction · 0.92
ErrMethod · 0.80
FinishMethod · 0.80
GetNameMethod · 0.65
GetSizeMethod · 0.65
ChunkLocationMethod · 0.45

Tested by

no test coverage detected