Download a multipart request (obj, [obj], fn) -> transformStream
326017
function downloadMultipart (headers, opts, handle) {
  if (!handle) {
    handle = opts
    opts = {}
  }

  assert.equal(typeof headers, 'object', 'multipart-stream: headers should be an object')
  assert.equal(typeof opts, 'object', 'multipart-stream: opts should be an object')
  assert.equal(typeof handle, 'function', 'multipart-stream: handle should be a function')

  opts = xtend(content.type(headers['content-type']), opts)
  var dispenser = new pez.Dispenser(opts)

  dispenser.on('part', function (part) {
    var encoding = part.headers['content-transfer-encoding']
    encoding = (encoding) ? encoding.toLowerCase() : '7bit'

    handle(part.name, part, part.filename, encoding, part.headers['content-type'])
  })

  return dispenser
}
7053
function through(transform, flush, objectMode) {
  const stream = new TransformStream({objectMode})
  stream._transform = transform || pass
  if (flush) stream._flush = flush
  return stream
}
1007837
def stream_download(self, data, callback):
        # type: (Union[requests.Response, ClientResponse], Callable) -> Iterator[bytes]
        
        block = self.config.connection.data_block_size
        try:
            # Assume this is ClientResponse, which it should be if backward compat was not important
            return cast(ClientResponse, data).stream_download(block, callback)
        except AttributeError:
            try:
                # Assume this is the patched requests.Response from "send"
                return data._universal_http_response.stream_download(block, callback)  # type: ignore
            except AttributeError:
                # Assume this is a raw requests.Response
                from .universal_http.requests import RequestsClientResponse
                response = RequestsClientResponse(None, data)
                return response.stream_download(block, callback)
712838
private RequestBody getBody(Map<String, String> data, @Nullable Map<String, File> files, @Nullable Map<String,
            InputStream> fileStreams) throws LocalOperationException {
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);

        if (files != null) {
            for (Map.Entry<String, File> entry : files.entrySet()) {
                File file = entry.getValue();
                String mimeType = URLConnection.guessContentTypeFromName(file.getName());

                if (mimeType == null) {
                    mimeType = "application/octet-stream";
                }

                builder.addFormDataPart(entry.getKey(), file.getName(),
                        RequestBody.create(MediaType.parse(mimeType), file));
            }
        }

        if (fileStreams != null) {
            for (Map.Entry<String, InputStream> entry : fileStreams.entrySet()) {
                byte[] bytes;
                InputStream stream = entry.getValue();
                try {
                    bytes = new byte[stream.available()];
                    stream.read(bytes);

                } catch (IOException e) {
                    throw new LocalOperationException(e);
                }
                builder.addFormDataPart(entry.getKey(), null,
                        RequestBody.create(MediaType.parse("application/octet-stream"), bytes));
            }
        }

        for (Map.Entry<String, String> entry : data.entrySet()) {
            builder.addFormDataPart(entry.getKey(), entry.getValue());
        }

        return builder.build();
    }
356419
function streamToText(stream) {
    return new Promise((fulfill, reject) => {
        let chunks = [];
        let length = 0;
        stream.setEncoding('utf8');
        stream.on('data', chunk => {
            length += chunk.length;
            if (length > MAX_TEXT_LENGTH) {
                reject(new Error('Response is too big'));
                return;
            }
            chunks.push(chunk);
        });
        stream.on('end', () => {
            fulfill(chunks.join(''));
        });
        stream.on('error', err => {
            reject(err);
        });
    });
}
651947
def stream_download(self, chunk_size: Optional[int] = None, callback: Optional[Callable] = None) -> AsyncIterator[bytes]:
        
        pass
1324840
function streamToString(callback) {
  var contents = '';

  return through(
    function (chunk, enc, next) {
      contents += chunk.toString('utf8');
      next();
    },
    function (next) { // flush function
      callback.bind(this)(contents, next);
    }
  );
}
435940
def download(ctx, archive_name, filepath, version):
    '''
    
    '''

    _generate_api(ctx)
    var = ctx.obj.api.get_archive(archive_name)

    if version is None:
        version = var.get_default_version()

    var.download(filepath, version=version)

    archstr = var.archive_name +\
        '' if (not var.versioned) else ' v{}'.format(version)

    click.echo('downloaded{} to {}'.format(archstr, filepath))
565523
function makeHttpRequests(options, fileHashes) {
    if (options.verbose) {
        _utils.logger.info('Performing HTTP requests...');
    }
    var promises = [];
    var _iteratorNormalCompletion4 = true;
    var _didIteratorError4 = false;
    var _iteratorError4 = undefined;

    try {
        for (var _iterator4 = fileHashes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
            var fileWithHash = _step4.value;

            if (fileWithHash.subtitlesPresent) continue;
            if (options.verbose) {
                _utils.logger.info('Downloading subtitles for file [%s] with hash [%s]', fileWithHash.file, fileWithHash.hash);
            }
            var httpRequest = new _utils.HttpRequest(options, fileWithHash);
            promises.push(httpRequest.request());
        }
    } catch (err) {
        _didIteratorError4 = true;
        _iteratorError4 = err;
    } finally {
        try {
            if (!_iteratorNormalCompletion4 && _iterator4.return) {
                _iterator4.return();
            }
        } finally {
            if (_didIteratorError4) {
                throw _iteratorError4;
            }
        }
    }

    return Promise.all(promises);
}
1362229
function _filesToStream (files, separator, callback) {

			if ("undefined" === typeof files) {
				throw new ReferenceError("missing \"files\" argument");
			}
				else if ("object" !== typeof files || !(files instanceof Array)) {
					throw new TypeError("\"files\" argument is not an Array");
				}
			else if ("undefined" === typeof callback && "undefined" === typeof separator) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof separator) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				const writeStream = new Transform();

				writeStream._transform = (chunk, enc, cb) => {
					writeStream.push(chunk);
					cb();
				};

				writeStream.once("error", () => {
					writeStream.end();
				});

				const _callback = "undefined" === typeof callback ? separator : callback;
				_callback(null, writeStream);

				_readContent(files, writeStream, "string" === typeof separator ? separator : " ").then(() => {
					writeStream.end();
					writeStream.emit("close");
				}).catch((err) => {
					writeStream.emit("error", err);
				});

			}

		}
1306286
def FromData(cls, stream, json_data, http=None, auto_transfer=None,
                 **kwds):
        """"""
        info = json.loads(json_data)
        missing_keys = cls._REQUIRED_SERIALIZATION_KEYS - set(info.keys())
        if missing_keys:
            raise exceptions.InvalidDataError(
                'Invalid serialization data, missing keys: %s' % (
                    ', '.join(missing_keys)))
        download = cls.FromStream(stream, **kwds)
        if auto_transfer is not None:
            download.auto_transfer = auto_transfer
        else:
            download.auto_transfer = info['auto_transfer']
        setattr(download, '_Download__progress', info['progress'])
        setattr(download, '_Download__total_size', info['total_size'])
        download._Initialize(  # pylint: disable=protected-access
            http, info['url'])
        return download
124368
function(url, options, fn){
        var r = request.post(url, fn);
        var form = r.form();
        form.append('field', options.field);
        form.append('files', fs.createReadStream(options.filepath));
        return form;
    }
295714
function handleVinylStream(sources, opt) {
  var collected = streamToArray(sources);

  return through2.obj(function (target, enc, cb) {
    if (target.isStream()) {
      return cb(error('Streams not supported for target templates!'));
    }
    collected.then(function (collection) {
      target.contents = getNewContent(target, collection, opt);
      this.push(target);
      cb();
    }.bind(this))
      .catch(function (error) {
        cb(error);
      });
  });
}
197872
def download_file(url, dst_path):
    """"""
    request = requests.get(url, stream=True)
    with open(dst_path, 'wb') as downloaded_file:
        request.raw.decode_content = True
        shutil.copyfileobj(request.raw, downloaded_file)
458691
function getCompressedStream(req, res) {
  var encoding = req.headers['accept-encoding'] || '';
  var stream;
  var contentEncodingHeader = res.getHeader('Content-Encoding');
  if ((contentEncodingHeader === 'gzip') || /\bgzip\b/.test(encoding)) {
    if (!contentEncodingHeader) {
      res.setHeader('Content-Encoding', 'gzip');
    }
    stream = zlib.createGzip();
    stream.pipe(res);
  } else if ((contentEncodingHeader === 'deflate') ||
      /\bdeflate\b/.test(encoding)) {
    if (!contentEncodingHeader) {
      res.setHeader('Content-Encoding', 'deflate');
    }
    stream = zlib.createDeflate();
    stream.pipe(res);
  }
  return stream;
}
230879
@WebOperationMethod
    public Map<String,Object> download(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String database = Objects.get(params, "database");
        String collection = Objects.get(params, "collection", COLLECTION);
        String id = Objects.get(params, "id");

        FileStorage.FileReadBean b = null;
        try{
            b = FileStorage.read(new Id(database,collection,id));
            response.setContentType(b.getMeta().getContentType());
            try {
                IOUtils.copy(b.getInputStream(), response.getOutputStream());
            } catch (IOException e) {
                throw S1SystemError.wrap(e);
            }
        }catch (NotFoundException e) {
            response.setStatus(404);
        }finally {
            FileStorage.closeAfterRead(b);
        }
        return null;
    }
804535
def download(url, dest):
    """"""
    path = os.path.join(dest, url.split('/')[-1])
    r = requests.get(url, stream=True)
    r.raise_for_status()
    with open(path, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:
                f.write(chunk)
    return path