Struct couchdb::attachment::Attachment [] [src]

pub struct Attachment { /* fields omitted */ }

Attachment is a state-aware representation of a CouchDB document attachment.

Summary

Remarks

CouchDB document attachments are versatile but tricky. Generally speaking, there are several things the application must get right:

TODO

Methods

impl Attachment
[src]

Constructs a new attachment.

The newly constructed Attachment is internally marked as having originated from the client and therefore, when serialized as JSON, will include all content as a base64-encoded string (as opposed to being stubbed out). This may incur significant overhead when sent to the CouchDB server within an enclosed document because base64-encoding uses four encoded bytes to represent every three encoded bytes.

One way to reduce base64 overhead is to stub the attachment and instead use multipart-encoding when uploading the document. See the CouchDB documentation for details.

Returns whether the attachment originates from the server.

Returns whether the attachment originates from the client.

Borrows the attachment's content MIME type.

Borrows the attachment's content, if available.

Content is available if and only if:

  • The attachment originates from the client, or,
  • The attachment originates from the server and is not a stub.

Returns the size of the attachment's content, in bytes.

Constructs a stubbed copy of the attachment.

A stubbed attachment contains no content, instead marking itself as a stub and relying on the CouchDB server to already have the content if the attachment is sent to the server within its enclosing document.

Hence, only an attachment that originates from the server can be stubbed. Otherwise, content would be lost, which this method prevents by instead returning None if the attachment originates from the client.

Note: The stub retains all other information about the attachment, such as content type and digest.

Constructs a stubbed copy of the attachment suitable for multipart-encoding.

The returned attachment loses all information about the attachment except for its content type and content length. The intention is for the application to:

  1. Serialize the attachment stub within an enclosed document, as JSON, and,

  2. Send the attachment content as multipart data, within the same HTTP request.

See the CouchDB documentation for details.

Example

extern crate couchdb;
extern crate mime;
extern crate serde_json;

let att = couchdb::Attachment::new(
    mime::TEXT_PLAIN,
    Vec::from(b"Lorem ipsum dolor sit amet".as_ref())
).to_multipart_stub();

let encoded = serde_json::to_vec(&att).unwrap();

// encoded:
//
// {
//     "content_type": "text/plain",
//     "follows": true,
//     "length": 26
// }

Borrows the attachment's digest, if available.

An attachment's digest is available if and only if it originates from the server.

Returns the attachment's encoding information, if available.

Returns the attachment's revision sequence number—i.e., the revpos attachment field.

Trait Implementations

impl Clone for Attachment
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Attachment
[src]

Formats the value using the given formatter.

impl Eq for Attachment
[src]

impl PartialEq for Attachment
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> Deserialize<'a> for Attachment
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Serialize for Attachment
[src]

Serialize this value into the given Serde serializer. Read more