quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

curl_mime_encoder.md (3009B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: curl_mime_encoder
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - curl_mime_addpart (3)
      9   - curl_mime_headers (3)
     10   - curl_mime_subparts (3)
     11 Protocol:
     12   - HTTP
     13   - IMAP
     14   - SMTP
     15 Added-in: 7.56.0
     16 ---
     17 
     18 # NAME
     19 
     20 curl_mime_encoder - set a mime part's encoder and content transfer encoding
     21 
     22 # SYNOPSIS
     23 
     24 ~~~c
     25 #include <curl/curl.h>
     26 
     27 CURLcode curl_mime_encoder(curl_mimepart *part, const char *encoding);
     28 ~~~
     29 
     30 # DESCRIPTION
     31 
     32 curl_mime_encoder() requests a mime part's content to be encoded before being
     33 transmitted.
     34 
     35 *part* is the part's handle to assign an encoder.
     36 *encoding* is a pointer to a null-terminated encoding scheme. It may be
     37 set to NULL to disable an encoder previously attached to the part. The encoding
     38 scheme storage may safely be reused after this function returns.
     39 
     40 Setting a part's encoder multiple times is valid: only the value set by the
     41 last call is retained.
     42 
     43 Upon multipart rendering, the part's content is encoded according to the
     44 pertaining scheme and a corresponding *"Content-Transfer-Encoding"* header
     45 is added to the part.
     46 
     47 Supported encoding schemes are:
     48 
     49 "*binary*": the data is left unchanged, the header is added.
     50 
     51 "*8bit*": header added, no data change.
     52 
     53 "*7bit*": the data is unchanged, but is each byte is checked
     54 to be a 7-bit value; if not, a read error occurs.
     55 
     56 "*base64*": Data is converted to base64 encoding, then split in
     57 CRLF-terminated lines of at most 76 characters.
     58 
     59 "*quoted-printable*": data is encoded in quoted printable lines of
     60 at most 76 characters. Since the resulting size of the final data cannot be
     61 determined prior to reading the original data, it is left as unknown, causing
     62 chunked transfer in HTTP. For the same reason, this encoder may not be used
     63 with IMAP. This encoder targets text data that is mostly ASCII and should
     64 not be used with other types of data.
     65 
     66 If the original data is already encoded in such a scheme, a custom
     67 *Content-Transfer-Encoding* header should be added with
     68 curl_mime_headers(3) instead of setting a part encoder.
     69 
     70 Encoding should not be applied to multiparts, thus the use of this function on
     71 a part with content set with curl_mime_subparts(3) is strongly
     72 discouraged.
     73 
     74 # %PROTOCOLS%
     75 
     76 # EXAMPLE
     77 
     78 ~~~c
     79 int main(void)
     80 {
     81   curl_mime *mime;
     82   curl_mimepart *part;
     83 
     84   CURL *curl = curl_easy_init();
     85   if(curl) {
     86     /* create a mime handle */
     87     mime = curl_mime_init(curl);
     88 
     89     /* add a part */
     90     part = curl_mime_addpart(mime);
     91 
     92     /* send a file */
     93     curl_mime_filedata(part, "image.png");
     94 
     95     /* encode file data in base64 for transfer */
     96     curl_mime_encoder(part, "base64");
     97   }
     98 }
     99 ~~~
    100 
    101 # %AVAILABILITY%
    102 
    103 # RETURN VALUE
    104 
    105 This function returns a CURLcode indicating success or error.
    106 
    107 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
    108 libcurl-errors(3). If CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3)
    109 there can be an error message stored in the error buffer when non-zero is
    110 returned.