<commit_before>var cryptostream = require('cryptostream');
var passStream = require('pass-stream');
var clamav = require('clamav.js');
var guid = require('shortid');
var mime = require('mime-types');
var Promise = require('es6-promise').Promise;
var headers = require('../../utils/headers');

module.exports = {
    select: function (request, reply) {
        var self = this;
        var guid = request.params.guid.split('.')[0];

        self.fs.find(guid, function (err, file) {
            if (err || file === null) {
                return reply({ 'statusCode': 404, 'error': 'Not Found' })
                    .code(404);
            }

            self.fs.read(guid, function (err, data) {
                if (err) {
                    return reply({ 'statusCode': 500, 'error': 'Internal Server Error', 'message': 'We encountered an unexpected readStream error.' })
                        .code(500);
                }

                var decryptStream = passStream();
                if (file.metadata.secure) {
                    decryptStream = new cryptostream.DecryptStream({ algorithm: request.params.algorithm || null, key: request.params.key || null });
                }

                return reply(data.pipe(decryptStream))
                    .header('Content-Disposition', headers.generateContentDisposition(file))
                    .header('Content-Type', (file.contentType || 'application/octet-stream'))
                    .header('ETag', file.md5)
                    .header('Last-Modified', file.uploadDate.toUTCString());
            });
        });
    }
};<commit_msg>send content-length with file stream<commit_after>var cryptostream = require('cryptostream');
var passStream = require('pass-stream');
var clamav = require('clamav.js');
var guid = require('shortid');
var mime = require('mime-types');
var Promise = require('es6-promise').Promise;
var headers = require('../../utils/headers');

module.exports = {
    select: function (request, reply) {
        var self = this;
        var guid = request.params.guid.split('.')[0];

        self.fs.find(guid, function (err, file) {
            if (err || file === null) {
                return reply({ 'statusCode': 404, 'error': 'Not Found' })
                    .code(404);
            }

            self.fs.read(guid, function (err, data) {
                if (err) {
                    return reply({ 'statusCode': 500, 'error': 'Internal Server Error', 'message': 'We encountered an unexpected readStream error.' })
                        .code(500);
                }

                var decryptStream = passStream();
                if (file.metadata.secure) {
                    decryptStream = new cryptostream.DecryptStream({ algorithm: request.params.algorithm || null, key: request.params.key || null });
                }

                return reply(data.pipe(decryptStream))
                    .header('Content-Disposition', headers.generateContentDisposition(file))
                    .header('Content-Length', file.length)
                    .header('Content-Type', (file.contentType || 'application/octet-stream'))
                    .header('ETag', file.md5)
                    .header('Last-Modified', file.uploadDate.toUTCString());
            });
        });
    }
};
{'fraction_non_alphanumeric': 0.14602307225258046, 'fraction_numerical': 0.009107468123861567, 'mean_word_length': 1.9498657117278424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7032745', 'n_tokens_mistral': 895, 'n_tokens_neox': 831, 'n_words': 196}