modules/orionode/lib/shared/tree.js
function putFile(req, res) {
		var rest = req.params["0"];
		var file = fileUtil.getFile(req, rest);
		var fileRoot = options.fileRoot;
		if (req.params['parts'] === 'meta') {
			// TODO implement put of file attributes
			return sendStatus(501, res);
		}
		function write() {
			var ws = fs.createWriteStream(file.path);
			ws.on('finish', function() {
				fileUtil.withStatsAndETag(file.path, function(error, stats, etag) {
					if (error && error.code === 'ENOENT') {
						return writeResponse(404, res);
					}
					writeFileMetadata(fileRoot, req, res, file.path, stats, etag);
				});
			});
			ws.on('error', function(err) {
				writeError(500, res, err);
			});
			req.pipe(ws);
		}
		var ifMatchHeader = req.headers['if-match'];
		fileUtil.withETag(file.path, function(error, etag) {
			if (error && error.code === 'ENOENT') {
				writeResponse(404, res);
			}
			else if (ifMatchHeader && ifMatchHeader !== etag) {
				writeResponse(412, res);
			}
			else {
				write();
			}
		});
	}
function putFile(req, res) {
		var rest = req.params["0"];
		var file = fileUtil.getFile(req, rest);
		var fileRoot = options.fileRoot;
		if (req.params['parts'] === 'meta') {
			// TODO implement put of file attributes
			return sendStatus(501, res);
		}
		function write() {
			var ws = fs.createWriteStream(file.path);
			ws.on('finish', function() {
				fileUtil.withStatsAndETag(file.path, function(error, stats, etag) {
					if (error && error.code === 'ENOENT') {
						return writeResponse(404, res);
					}
					writeFileMetadata(fileRoot, req, res, file.path, stats, etag);
				});
			});
			ws.on('error', function(err) {
				writeError(500, res, err);
			});
			req.pipe(ws);
		}
		var ifMatchHeader = req.headers['if-match'];
		fileUtil.withETag(file.path, function(error, etag) {
			if (error && error.code === 'ENOENT') {
				writeResponse(404, res);
			}
			else if (ifMatchHeader && ifMatchHeader !== etag) {
				writeResponse(412, res);
			}
			else {
				write();
			}
		});
	}
function putFile ( req , res ) { var rest = req . params [ "0" ] ; var file = fileUtil . getFile ( req , rest ) ; var fileRoot = options . fileRoot ; if ( req . params [ 'parts' ] === 'meta' ) { // TODO implement put of file attributes return sendStatus ( 501 , res ) ; } function write ( ) { var ws = fs . createWriteStream ( file . path ) ; ws . on ( 'finish' , function ( ) { fileUtil . withStatsAndETag ( file . path , function ( error , stats , etag ) { if ( error && error . code === 'ENOENT' ) { return writeResponse ( 404 , res ) ; } writeFileMetadata ( fileRoot , req , res , file . path , stats , etag ) ; } ) ; } ) ; ws . on ( 'error' , function ( err ) { writeError ( 500 , res , err ) ; } ) ; req . pipe ( ws ) ; } var ifMatchHeader = req . headers [ 'if-match' ] ; fileUtil . withETag ( file . path , function ( error , etag ) { if ( error && error . code === 'ENOENT' ) { writeResponse ( 404 , res ) ; } else if ( ifMatchHeader && ifMatchHeader !== etag ) { writeResponse ( 412 , res ) ; } else { write ( ) ; } } ) ; }
For file save.
For file save .