"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "delayedMemoryStorage", {
    enumerable: true,
    get: function() {
        return delayedMemoryStorage;
    }
});
const delayedMemoryStorage = ()=>{
    return {
        _handleFile (req, file, cb) {
            let chunks = [];
            let processingComplete = Promise.resolve();
            console.log(`Processing file upload name ${file.originalname} field ${file.fieldname} size ${file.size}`);
            file.stream.on("data", (chunk)=>{
                chunks.push(chunk);
                processingComplete = processingComplete.then(new Promise((resolve)=>{
                    return setTimeout(()=>{
                        chunks.push(chunk);
                        resolve(null);
                    }, 1);
                }));
            });
            file.stream.on("end", ()=>{
                cb(null, {
                    buffer: Buffer.concat(chunks),
                    size: Buffer.concat(chunks).length
                });
            });
            file.stream.on("error", (err)=>{
                cb(err);
            });
        },
        _removeFile (req, file, cb) {
            cb(null);
        }
    };
};

//# sourceMappingURL=delayed-memory.storage.js.map