<commit_before>"use strict";
var _ = require('lodash'),
    request = require('request');

module.exports = function (url, headers) {
    var defer = Promise.defer();
    request({url, headers})
        .on('response', function (_response) {
            if (!_.contains([200, 206], _response.statusCode)) {
                throw Error(_response.statusMessage);
            }
            _response.pause();
            defer.resolve({
                read: function * () {
                    var chunk;
                    while (null !== (chunk = _response.read())) {
                        yield chunk;
                    }
                }
            });
        });
<commit_msg>Http Request 's response is readable<commit_after>"use strict";
var _ = require('lodash'),
    request = require('request');

module.exports = function (url, headers) {
    var defer = Promise.defer(),
        response,
        data = [],
        done = false,
        resolve = _.once(() => defer.resolve({read, response})),
        read = function * () {
            while (data.length > 0) {
                yield data.shift();
            }
        };
    request({url, headers})
        .on('response', (x) => response = x)
        .on('data', (buffer) => data.push(buffer))
        .on('data', resolve)
        .on('complete', () => done = true);
{'fraction_non_alphanumeric': 0.156203288490284, 'fraction_numerical': 0.00523168908819133, 'mean_word_length': 1.6726546906187625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1300420', 'n_tokens_mistral': 364, 'n_tokens_neox': 342, 'n_words': 83}