var path = require( 'path' );
var fs = require( 'fs' );
var mkdir_p = function (pth, callback)
{
fs.stat(pth, function (err, stat)
{
if (!err && stat)
{
callback( null );
return ;
}
mkdir_p(path.dirname(pth), function (err)
{
if (err)
{
callback(err);
return ;
}
fs.mkdir(pth, 0755, callback);
});
});
};
* This source code was highlighted with Source Code Highlighter .
mkdir_p(path.dirname(outPath), function (err)
{
if (err)
{
response.writeHead(500, { 'Content-Type' : 'text/plain' });
response.end( 'Cannot create directory' );
return ;
}
getFile(url, inPath, function (err)
{
if (err)
{
response.writeHead(500, { 'Content-Type' : 'text/plain' });
response.end( 'Cannot read file' );
return ;
}
transcode(inPath, outPath, function (err)
{
if (err)
{
response.writeHead(500, { 'Content-Type' : 'text/plain' });
response.end( 'Cannot transcode file' );
return ;
}
sendRemoveFile(outPath, response, function (err)
{
if (err)
{
console.log( 'Cannot send file' );
return ;
}
});
});
});
});
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/102717/
All Articles