| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package buildbot | 5 package buildbot |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "compress/gzip" | 9 "compress/gzip" |
| 10 "encoding/json" | 10 "encoding/json" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 builder.CachedBuilds = make([]int, len(builds)) | 87 builder.CachedBuilds = make([]int, len(builds)) |
| 88 for i, b := range builds { | 88 for i, b := range builds { |
| 89 builder.CachedBuilds[i] = b.Number | 89 builder.CachedBuilds[i] = b.Number |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 // And re-compress it. | 93 // And re-compress it. |
| 94 gzbs := bytes.Buffer{} | 94 gzbs := bytes.Buffer{} |
| 95 gsw := gzip.NewWriter(&gzbs) | 95 gsw := gzip.NewWriter(&gzbs) |
| 96 defer gsw.Close() | |
| 97 cw := iotools.CountingWriter{Writer: gsw} | 96 cw := iotools.CountingWriter{Writer: gsw} |
| 98 e := json.NewEncoder(&cw) | 97 e := json.NewEncoder(&cw) |
| 99 if err := e.Encode(master); err != nil { | 98 if err := e.Encode(master); err != nil { |
| 99 gsw.Close() |
| 100 return nil, err | 100 return nil, err |
| 101 } | 101 } |
| 102 gsw.Close() |
| 102 | 103 |
| 103 logging.Infof(c, "Returning %d bytes", cw.Count) | 104 logging.Infof(c, "Returning %d bytes", cw.Count) |
| 104 | 105 |
| 105 return &milo.CompressedMasterJSON{ | 106 return &milo.CompressedMasterJSON{ |
| 106 Internal: entry.Internal, | 107 Internal: entry.Internal, |
| 107 Modified: &google.Timestamp{ | 108 Modified: &google.Timestamp{ |
| 108 Seconds: entry.Modified.Unix(), | 109 Seconds: entry.Modified.Unix(), |
| 109 Nanos: int32(entry.Modified.Nanosecond()), | 110 Nanos: int32(entry.Modified.Nanosecond()), |
| 110 }, | 111 }, |
| 111 Data: gzbs.Bytes(), | 112 Data: gzbs.Bytes(), |
| 112 }, nil | 113 }, nil |
| 113 } | 114 } |
| OLD | NEW |