MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / writeJSONPart

Function writeJSONPart

rest/multipart.go:96–123  ·  view source on GitHub ↗
(writer *multipart.Writer, contentType string, body db.Body, compressed bool)

Source from the content-addressed store, hash-verified

94}
95
96func writeJSONPart(writer *multipart.Writer, contentType string, body db.Body, compressed bool) (err error) {
97 bytes, err := base.JSONMarshalCanonical(body)
98 if err != nil {
99 return err
100 }
101 if len(bytes) < kMinCompressedJSONSize {
102 compressed = false
103 }
104
105 partHeaders := textproto.MIMEHeader{}
106 partHeaders.Set("Content-Type", contentType)
107 if compressed {
108 partHeaders.Set("Content-Encoding", "gzip")
109 }
110 part, err := writer.CreatePart(partHeaders)
111 if err != nil {
112 return err
113 }
114
115 if compressed {
116 gz := gzip.NewWriter(part)
117 _, err = gz.Write(bytes)
118 _ = gz.Close()
119 } else {
120 _, err = part.Write(bytes)
121 }
122 return
123}
124
125// Writes a revision to a MIME multipart writer, encoding large attachments as separate parts.
126func WriteMultipartDocument(ctx context.Context, cblReplicationPullStats *base.CBLReplicationPullStats, body db.Body, writer *multipart.Writer, compress bool) {

Callers 3

WriteMultipartDocumentFunction · 0.85
WriteRevisionAsPartFunction · 0.85
TestWriteJSONPartFunction · 0.85

Calls 4

JSONMarshalCanonicalFunction · 0.92
CloseMethod · 0.65
SetMethod · 0.45
WriteMethod · 0.45

Tested by 1

TestWriteJSONPartFunction · 0.68