diff options
author | Wim <wim@42.be> | 2016-11-20 17:02:17 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2016-11-20 17:02:17 +0100 |
commit | 94ea775232eabfd3945ef9b5d6e93e3505fd4a99 (patch) | |
tree | 9930dd9d68cee5e7b8153d3e3345539f21fe1fbe /vendor/github.com/technoweenie | |
parent | 449ed31e25f2c21ac9db258999a5a893889983eb (diff) | |
parent | 2e4b7fac1146c186f28599d62379d7e9912fda81 (diff) | |
download | matterbridge-msglm-94ea775232eabfd3945ef9b5d6e93e3505fd4a99.tar.gz matterbridge-msglm-94ea775232eabfd3945ef9b5d6e93e3505fd4a99.tar.bz2 matterbridge-msglm-94ea775232eabfd3945ef9b5d6e93e3505fd4a99.zip |
Merge branch 'telegram'
Add telegram support
Diffstat (limited to 'vendor/github.com/technoweenie')
4 files changed, 166 insertions, 0 deletions
diff --git a/vendor/github.com/technoweenie/multipartstreamer/LICENSE b/vendor/github.com/technoweenie/multipartstreamer/LICENSE new file mode 100644 index 00000000..20d92fba --- /dev/null +++ b/vendor/github.com/technoweenie/multipartstreamer/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2013-* rick olson + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/technoweenie/multipartstreamer/examples/multipart.go b/vendor/github.com/technoweenie/multipartstreamer/examples/multipart.go new file mode 100644 index 00000000..971078be --- /dev/null +++ b/vendor/github.com/technoweenie/multipartstreamer/examples/multipart.go @@ -0,0 +1,31 @@ +package main + +import ( + "bytes" + "flag" + "fmt" + "io" + "mime/multipart" + "os" + "path/filepath" +) + +func main() { + defaultPath, _ := os.Getwd() + defaultFile := filepath.Join(defaultPath, "streamer.go") + fullpath := flag.String("path", defaultFile, "Path to the include in the multipart data.") + flag.Parse() + + buffer := bytes.NewBufferString("") + writer := multipart.NewWriter(buffer) + + fmt.Println("Adding the file to the multipart writer") + fileWriter, _ := writer.CreateFormFile("file", *fullpath) + fileData, _ := os.Open(*fullpath) + io.Copy(fileWriter, fileData) + writer.Close() + + fmt.Println("Writing the multipart data to a file") + output, _ := os.Create("multiparttest") + io.Copy(output, buffer) +} diff --git a/vendor/github.com/technoweenie/multipartstreamer/examples/streamer.go b/vendor/github.com/technoweenie/multipartstreamer/examples/streamer.go new file mode 100644 index 00000000..324f7e12 --- /dev/null +++ b/vendor/github.com/technoweenie/multipartstreamer/examples/streamer.go @@ -0,0 +1,27 @@ +package main + +import ( + "flag" + "fmt" + "github.com/technoweenie/multipartstreamer" + "io" + "os" + "path/filepath" +) + +func main() { + defaultPath, _ := os.Getwd() + defaultFile := filepath.Join(defaultPath, "streamer.go") + fullpath := flag.String("path", defaultFile, "Path to the include in the multipart data.") + flag.Parse() + + ms := multipartstreamer.New() + + fmt.Println("Adding the file to the multipart writer") + ms.WriteFile("file", *fullpath) + reader := ms.GetReader() + + fmt.Println("Writing the multipart data to a file") + file, _ := os.Create("streamtest") + io.Copy(file, reader) +} diff --git a/vendor/github.com/technoweenie/multipartstreamer/multipartstreamer.go b/vendor/github.com/technoweenie/multipartstreamer/multipartstreamer.go new file mode 100644 index 00000000..26d8e850 --- /dev/null +++ b/vendor/github.com/technoweenie/multipartstreamer/multipartstreamer.go @@ -0,0 +1,101 @@ +/* +Package multipartstreamer helps you encode large files in MIME multipart format +without reading the entire content into memory. It uses io.MultiReader to +combine an inner multipart.Reader with a file handle. +*/ +package multipartstreamer + +import ( + "bytes" + "fmt" + "io" + "io/ioutil" + "mime/multipart" + "net/http" + "os" + "path/filepath" +) + +type MultipartStreamer struct { + ContentType string + bodyBuffer *bytes.Buffer + bodyWriter *multipart.Writer + closeBuffer *bytes.Buffer + reader io.Reader + contentLength int64 +} + +// New initializes a new MultipartStreamer. +func New() (m *MultipartStreamer) { + m = &MultipartStreamer{bodyBuffer: new(bytes.Buffer)} + + m.bodyWriter = multipart.NewWriter(m.bodyBuffer) + boundary := m.bodyWriter.Boundary() + m.ContentType = "multipart/form-data; boundary=" + boundary + + closeBoundary := fmt.Sprintf("\r\n--%s--\r\n", boundary) + m.closeBuffer = bytes.NewBufferString(closeBoundary) + + return +} + +// WriteFields writes multiple form fields to the multipart.Writer. +func (m *MultipartStreamer) WriteFields(fields map[string]string) error { + var err error + + for key, value := range fields { + err = m.bodyWriter.WriteField(key, value) + if err != nil { + return err + } + } + + return nil +} + +// WriteReader adds an io.Reader to get the content of a file. The reader is +// not accessed until the multipart.Reader is copied to some output writer. +func (m *MultipartStreamer) WriteReader(key, filename string, size int64, reader io.Reader) (err error) { + m.reader = reader + m.contentLength = size + + _, err = m.bodyWriter.CreateFormFile(key, filename) + return +} + +// WriteFile is a shortcut for adding a local file as an io.Reader. +func (m *MultipartStreamer) WriteFile(key, filename string) error { + fh, err := os.Open(filename) + if err != nil { + return err + } + + stat, err := fh.Stat() + if err != nil { + return err + } + + return m.WriteReader(key, filepath.Base(filename), stat.Size(), fh) +} + +// SetupRequest sets up the http.Request body, and some crucial HTTP headers. +func (m *MultipartStreamer) SetupRequest(req *http.Request) { + req.Body = m.GetReader() + req.Header.Add("Content-Type", m.ContentType) + req.ContentLength = m.Len() +} + +func (m *MultipartStreamer) Boundary() string { + return m.bodyWriter.Boundary() +} + +// Len calculates the byte size of the multipart content. +func (m *MultipartStreamer) Len() int64 { + return m.contentLength + int64(m.bodyBuffer.Len()) + int64(m.closeBuffer.Len()) +} + +// GetReader gets an io.ReadCloser for passing to an http.Request. +func (m *MultipartStreamer) GetReader() io.ReadCloser { + reader := io.MultiReader(m.bodyBuffer, m.reader, m.closeBuffer) + return ioutil.NopCloser(reader) +} |