Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Replace PutObject with composed struct #21

Open
msiebuhr opened this issue Nov 23, 2018 · 0 comments
Open

Replace PutObject with composed struct #21

msiebuhr opened this issue Nov 23, 2018 · 0 comments

Comments

@msiebuhr
Copy link
Owner

msiebuhr commented Nov 23, 2018

We have a frequent use for getting some file contents and knowing its size up-front; in the client when we want to upload things and in the server when we return things.

A rough sketch:

package main

import (
	"fmt"
	"io"
	"os"
)

type SizeReader interface {
	io.Reader
	Size() int64
}

type SizeFile struct {
	*os.File
}

func (sf *SizeFile) Size() int64 {
	stat, _ := sf.Stat()
	if stat == nil {
		return 0
	}
	return stat.Size()
}

// Add things that makes sized random readers, network, ...

func main() {
	x, err := os.Open("./test.go")
	if err != nil {
		panic(err)
	}
	sf := &SizeFile{x}
	fmt.Println(x, err, sf.Size())
}

Would also be useful for the streaming put/get interfaces...

@msiebuhr msiebuhr changed the title Replace PutObject with compsed struct Replace PutObject with composed struct Nov 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant