本文整理汇总了Golang中bytes.NewReader函数的典型用法代码### 示例。如果您正苦于以下问题:Golang NewReader函数的具体用法?Golang NewReader怎么用?Golang NewReader使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了NewReader函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: Fuzz
func Fuzz(data []byte) int {
cfg, err := gif.DecodeConfig(bytes.NewReader(data))
if err != nil {
return 0
}
if cfg.Width*cfg.Height > 1e6 {
return 0
}
img, err := gif.Decode(bytes.NewReader(data))
if err != nil {
return 0
}
for c := 1; c <= 256; c += 21 {
var w bytes.Buffer
err = gif.Encode(&w, img, &gif.Options{NumColors: c})
if err != nil {
panic(err)
}
img1, err := gif.Decode(&w)
if err != nil {
panic(err)
}
b0 := img.Bounds()
b1 := img1.Bounds()
if b0.Max.X-b0.Min.X != b1.Max.X-b1.Min.X || b0.Max.Y-b0.Min.Y != b1.Max.Y-b1.Min.Y {
fmt.Printf("img0: %#v\n", img.Bounds())
fmt.Printf("img1: %#v\n", img1.Bounds())
panic("bounds changed")
}
}
return 1
}
开发者ID:rlmcpherson,项目名称:go-fuzz,代码行数:32,代码来源:gif.go
示例2: FetchUser
// FetchUser will go to Cloud Foundry and access basic information about the user.
func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
s := session.(*Session)
user := goth.User{
AccessToken: s.AccessToken,
Provider: p.Name(),
RefreshToken: s.RefreshToken,
ExpiresAt: s.ExpiresAt,
}
req, err := http.NewRequest("GET", p.UserInfoURL, nil)
if err != nil {
return user, err
}
req.Header.Set("Authorization", "Bearer "+s.AccessToken)
resp, err := p.Client.Do(req)
if err != nil {
if resp != nil {
resp.Body.Close()
}
return user, err
}
defer resp.Body.Close()
bits, err := ioutil.ReadAll(resp.Body)
if err != nil {
return user, err
}
err = json.NewDecoder(bytes.NewReader(bits)).Decode(&user.RawData)
if err != nil {
return user, err
}
err = userFromReader(bytes.NewReader(bits), &user)
return user, err
}
开发者ID:starkandwayne,项目名称:shield,代码行数:36,代码来源:cf.go
示例3: PutPage
// PutPage writes a range of pages to a page blob or clears the given range.
// In case of 'clear' writes, given chunk is discarded. Ranges must be aligned
// with 512-byte boundaries and chunk must be of size multiplies by 512.
//
// See https://msdn.microsoft.com/en-us/library/ee691975.aspx
func (b BlobStorageClient) PutPage(container, name string, startByte, endByte int64, writeType PageWriteType, chunk []byte, extraHeaders map[string]string) error {
path := fmt.Sprintf("%s/%s", container, name)
uri := b.client.getEndpoint(blobServiceName, path, url.Values{"comp": {"page"}})
headers := b.client.getStandardHeaders()
headers["x-ms-blob-type"] = string(BlobTypePage)
headers["x-ms-page-write"] = string(writeType)
headers["x-ms-range"] = fmt.Sprintf("bytes=%v-%v", startByte, endByte)
for k, v := range extraHeaders {
headers[k] = v
}
var contentLength int64
var data io.Reader
if writeType == PageWriteTypeClear {
contentLength = 0
data = bytes.NewReader([]byte{})
} else {
contentLength = int64(len(chunk))
data = bytes.NewReader(chunk)
}
headers["Content-Length"] = fmt.Sprintf("%v", contentLength)
resp, err := b.client.exec("PUT", uri, headers, data)
if err != nil {
return err
}
defer resp.body.Close()
return checkRespCode(resp.statusCode, []int{http.StatusCreated})
}
开发者ID:RaulKite,项目名称:machine,代码行数:34,代码来源:blob.go
示例4: TestFuncs
func (s *TestSuite) TestFuncs(c *C) {
var err error
body := []byte("this is only a test file")
key := "test_file"
key1 := "test_file_1"
key2 := "test_file_2"
err = s.service.PutObject(key1, bytes.NewReader(body))
c.Assert(err, IsNil)
err = s.service.PutObject(key2, bytes.NewReader(body))
c.Assert(err, IsNil)
objs, err := s.service.ListObjects(key)
c.Assert(err, IsNil)
c.Assert(objs, HasLen, 2)
r, err := s.service.GetObject(key1)
c.Assert(err, IsNil)
newBody, err := ioutil.ReadAll(r)
c.Assert(err, IsNil)
c.Assert(newBody, DeepEquals, body)
err = s.service.DeleteObjects([]string{key})
c.Assert(err, IsNil)
objs, err = s.service.ListObjects(key)
c.Assert(err, IsNil)
c.Assert(objs, HasLen, 0)
}
开发者ID:deniseschannon,项目名称:rancher-volume,代码行数:31,代码来源:s3_service_test.go
示例5: TestMultiComplete
// This may take a minute or more due to the minimum size accepted S3
// on multipart upload parts.
func (s *ClientTests) TestMultiComplete(c *gocheck.C) {
b := testBucket(s.s3)
err := b.PutBucket(s3.Private)
c.Assert(err, gocheck.IsNil)
multi, err := b.InitMulti("multi", "text/plain", s3.Private)
c.Assert(err, gocheck.IsNil)
c.Assert(multi.UploadId, gocheck.Matches, ".+")
defer multi.Abort()
// Minimum size S3 accepts for all but the last part is 5MB.
data1 := make([]byte, 5*1024*1024)
data2 := []byte("<part 2>")
part1, err := multi.PutPart(1, bytes.NewReader(data1))
c.Assert(err, gocheck.IsNil)
part2, err := multi.PutPart(2, bytes.NewReader(data2))
c.Assert(err, gocheck.IsNil)
// Purposefully reversed. The order requirement must be handled.
err = multi.Complete([]s3.Part{part2, part1})
c.Assert(err, gocheck.IsNil)
data, err := b.Get("multi")
c.Assert(err, gocheck.IsNil)
c.Assert(len(data), gocheck.Equals, len(data1)+len(data2))
for i := range data1 {
if data[i] != data1[i] {
c.Fatalf("uploaded object at byte %d: want %d, got %d", data1[i], data[i])
}
}
c.Assert(string(data[len(data1):]), gocheck.Equals, string(data2))
}
开发者ID:dutchcoders,项目名称:goamz,代码行数:36,代码来源:s3i_test.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng