Tag: 文件写入

对服务器中文件的连续写入很慢

我想用MEAN模块构build一个简单的操作系统,模拟plunker:我们有一个文件列表,左侧是textarea,右侧是实时预览。 请注意,文件保存在临时文件夹中,实时预览是由临时文件夹中的文件注入的iframe 。 我编写了一些东西。 在前端,控制器监视textarea中文件的修改; 每次有变化, render将被调用,它会发送一个$http.post来保存所有文件的新版本。 app.controller('Ctrl', ['$scope', 'codeService', function ($scope, codeService) { … $scope.$watch('files', function () { codeService.render($scope.files) }, true); }]); app.service('codeService', ['$http', function ($http) { this.render = function (files) { … var arrayLength = files.length; for (var i = 0; i < arrayLength; i++) { $http.post('/writeFile', files[i]); } } } 在后端: router.post('/writeFile', […]

在writeFile期间nodejs进程崩溃时,文件会发生什么情况?

如果在fs.writeFile操作期间Node.js主进程崩溃,我的问题是: 会发生什么文件? 写操作是否会停止,导致只写一半? 如果写入标志是'w',那么文件只存储一半的数据? 我怎样才能避免这种情况,并确保我可以存储没有数据或完整的数据? 也许将标志设置为“a”是一个解决scheme。 任何其他更好的想法?