title: ESP8266 WebServer how to stream unsigned char
body: <p>I was playing around with xxd -i this weekend to convert binary files into unsigned char arrays, thinking I could use it to embed small binary files into arduino code for transmission on mini web and other services. Problem is, it seems the functions in the existing libraries either expect const char *, string or File data types. (and of course, unsigned char arrays aren't really char arrays so they don't convert well to strings)</p>
  
  <p>Not being someone familiar with c++ in depth (still learning) I'm wondering if there is any easy way to stream the unsigned char array created from xxd over the ESP webserver code or something similar? And/or is there a better way to encode a binary file for sending from same?</p>
  
  <p>I'm basically looking at building primarily 'rest' based esp devices, but wanted to have some kind of very rudimentary html/js interface to directly connect and configure basic functionality or get basic telemetry back from the devices. My thought was that with very streamline html/js coding combined with a minify followed by a gzip, I could put such basic primitive interfaces directly into the code in a binary array to be served up when needed. For more complex devices, I've gotten the sd card webserver to work fine, but would prefer not to have to use sd cards for all applications. Before I go back to relying upon html content in huge strings or function calls full of concatenations/prints, I'd like to try to get this to work as another option.
  Any help is appreciated.</p>
  
  <p>--- EDITED ---
  Example from xxd -i</p>
  
  <pre><code>unsigned char index_htm_gz[] = {
      0x1f, 0x8b, 0x08, 0x08, 0x25, 0x38, 0xcf, 0x58, 0x02, 0x03, 0x69, 0x6e,
      0x64, 0x65, 0x78, 0x2e, 0x6d, 0x69, 0x6e, 0x2e, 0x68, 0x74, 0x6d, 0x00,
      0x5d, 0x8d, 0xb1, 0x6a, 0xc4, 0x30, 0x10, 0x44, 0x7b, 0x7d, 0xc5, 0xe6,
      0x03, 0xce, 0x4a, 0xc0, 0x98, 0x14, 0x2b, 0x35, 0x97, 0x40, 0xba, 0x4b,
      0x61, 0x08, 0x29, 0x65, 0x7b, 0x2d, 0x2d, 0xb7, 0xb2, 0x8d, 0xb4, 0xc9,
      0x91, 0xbf, 0x8f, 0x42, 0xba, 0x83, 0x61, 0x18, 0x1e, 0x33, 0x0c, 0x3e,
      0xbc, 0x5c, 0xce, 0xe3, 0xe7, 0xfb, 0x2b, 0x24, 0xcd, 0xe2, 0xf1, 0xcf,
      0x41, 0xc2, 0x16, 0x1d, 0x6d, 0x1e, 0x33, 0x69, 0x80, 0x39, 0x85, 0x52,
      0x49, 0xdd, 0x97, 0xae, 0xa7, 0x67, 0x8f, 0xca, 0x2a, 0xe4, 0xdf, 0x48,
      0x64, 0x07, 0xf3, 0xb1, 0x17, 0x59, 0xd0, 0xfe, 0x33, 0x14, 0xde, 0xae,
      0x90, 0x0a, 0xad, 0x6e, 0xae, 0xd5, 0xe6, 0xc0, 0x5b, 0xd7, 0x02, 0x14,
      0x12, 0x57, 0xf5, 0x47, 0xa8, 0x26, 0x22, 0x6d, 0x1f, 0x4f, 0x77, 0xf3,
      0x06, 0xf0, 0xf0, 0x63, 0xe2, 0x0a, 0x4d, 0x01, 0x6e, 0x34, 0xc1, 0x11,
      0x22, 0x75, 0x68, 0x0f, 0x8f, 0x9c, 0x23, 0x4c, 0x7b, 0x59, 0xa8, 0xb8,
      0x47, 0x48, 0xc4, 0x31, 0xa9, 0x1b, 0x7a, 0x30, 0xb5, 0xcc, 0x8e, 0x73,
      0xab, 0x55, 0xfb, 0x3d, 0x45, 0xda, 0x87, 0xbe, 0x8b, 0xbc, 0xc2, 0x8d,
      0x17, 0x4d, 0xad, 0xe0, 0x8d, 0xf9, 0x05, 0x3d, 0x2a, 0xb3, 0xe0, 0xdd,
      0x00, 0x00, 0x00
  };
  unsigned int index_htm_gz_len = 207;
  </code></pre>
  
  <p>As mentioned in comments, one thing I tried was switching the type from unsigned char to const char then running through the following:</p>
  
  <pre><code>void sendCompressed(String content_type, const char * content, unsigned int len) {
      webServer.setContentLength(len);
      webServer.sendHeader("Content-Encoding", "gzip");
      webServer.send(200, content_type, String(content));
  }
  </code></pre>
  
  <p>In such a case, my handleRoot function would call the sendCompressed with the data from the header:</p>
  
  <pre><code>void function handleRoot() {
      sendCompressed("text/html", index_htm_gz, index_htm_gz_len);
  }
  </code></pre>
  
  <p>It compiled without errors, but outputs nothing. I would also expect this not to be ideal as String data is generally 7-bit and obviously, binary compressed data is not.</p>