Skip to content

Commit 035a1a6

Browse files
author
TAV2BJ
committed
Allows to disable making parent collection while writing stream
1 parent f9157db commit 035a1a6

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

client.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -416,22 +416,19 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
416416
}
417417

418418
// WriteStream writes a stream
419-
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error) {
420-
421-
err = c.createParentCollection(path)
422-
if err != nil {
423-
return err
419+
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode, dontMakeParents ...bool) (err error) {
420+
if len(dontMakeParents) == 0 {
421+
if err := c.createParentCollection(path); err != nil {
422+
return err
423+
}
424424
}
425-
426425
s, err := c.put(path, stream)
427426
if err != nil {
428427
return err
429428
}
430-
431429
switch s {
432430
case 200, 201, 204:
433431
return nil
434-
435432
default:
436433
return NewPathError("WriteStream", path, s)
437434
}

client_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ func TestWriteStream(t *testing.T) {
543543
if info, err := fs.Stat(ctx, "/404/works.txt"); err != nil {
544544
t.Fatalf("got: %v, want file info: %v", err, info)
545545
}
546+
547+
if err := cli.WriteStream("/test/newFile.txt", strings.NewReader("foo bar\n"), 0660, false); err != nil {
548+
t.Fatalf("got: %v, want nil", err)
549+
}
550+
551+
if info, err := fs.Stat(ctx, "/test/newFile.txt"); err != nil {
552+
t.Fatalf("got: %v, want file info: %v", err, info)
553+
}
546554
}
547555

548556
func TestWriteStreamFromPipe(t *testing.T) {

0 commit comments

Comments
 (0)