lib/middleware/ai.js
function putCache() {
      return new Promise(function(resolve, reject) {
        // make the cache key
        let key = getKey();

        // adapt the image
        adapt(function(err, stdout, stderr) {
          if (err) {
            return reject(err);
          }

          // convert the new image stream to buffer
          stream2buffer(stdout, function(err, buffer) {
            if (err) {
              return reject(err);
            }

            if (!buffer || !buffer.length) {
              return resolve(buffer);
            }

            // put the buffer in the cache
            put(key, buffer, function(err, data) {
              if (err) {
                log(`Cache set failure: ${err instanceof Error ? err.message : err}`);
              }

              // return the buffer
              resolve(buffer);
            });
          });
        });
      });
    }
function putCache() {
      return new Promise(function(resolve, reject) {
        // make the cache key
        let key = getKey();

        // adapt the image
        adapt(function(err, stdout, stderr) {
          if (err) {
            return reject(err);
          }

          // convert the new image stream to buffer
          stream2buffer(stdout, function(err, buffer) {
            if (err) {
              return reject(err);
            }

            if (!buffer || !buffer.length) {
              return resolve(buffer);
            }

            // put the buffer in the cache
            put(key, buffer, function(err, data) {
              if (err) {
                log(`Cache set failure: ${err instanceof Error ? err.message : err}`);
              }

              // return the buffer
              resolve(buffer);
            });
          });
        });
      });
    }
function putCache ( ) { return new Promise ( function ( resolve , reject ) { // make the cache key let key = getKey ( ) ; // adapt the image adapt ( function ( err , stdout , stderr ) { if ( err ) { return reject ( err ) ; } // convert the new image stream to buffer stream2buffer ( stdout , function ( err , buffer ) { if ( err ) { return reject ( err ) ; } if ( ! buffer || ! buffer . length ) { return resolve ( buffer ) ; } // put the buffer in the cache put ( key , buffer , function ( err , data ) { if ( err ) { log ( ` ${ err instanceof Error ? err . message : err } ` ) ; } // return the buffer resolve ( buffer ) ; } ) ; } ) ; } ) ; } ) ; }
Creates an adapted image buffer | puts it in the cache | returns the buffer

@returns {Promise}
Creates an adapted image buffer | puts it in the cache | returns the buffer