我正在开发一款可以转发发送到投递箱的视频的应用。由于视频可能需要几分钟到几个小时才能发送到Dropbox,因此我希望确保文件在我的应用开始处理之前完成。
我认为最简单的方法是使用为dropbox编制索引的守护进程的每次传递来检查文件的大小。如果两次或多次传递的文件大小保持不变,则应用程序可以假定文件已完成写入。
然而,当我在我的应用程序的Rails控制台中弄乱这个时,似乎正在缓存文件大小。当我将视频文件导出到投递箱目录时,我看到了这一点。在OS X 10.6 finder中,文件大小在写入视频时不断更新。如果我运行File.size怎么办?在正在写入的文件上,我重复获得相同的大小,直到它随机更新。下面是一些示例输出,我正在运行File.size?方法大约每秒一次。
有什么我想念的吗?
感谢。
File.size?("/Volumes/FCP_Edit/ProgramingDropBox/test.mov")
=> 95053324
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/test.mov")
=> 95053324
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 23769068
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 23769068
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 23769068
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 23769068
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 23769068
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 23769068
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 64888832
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 123609088
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 336691200
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 336691200
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 336691200
>> File.size?("/Volumes/FCP_Edit/ProgramingDropBox/dumb.mov")
=> 336691200
答案 0 :(得分:0)
我不习惯Ruby,但看起来它正在读取文件大小,就像磁盘中的空间一样,而不是以字节为单位的实际大小。
因为每个文件通常至少占用磁盘的一个扇区,无论实际文件大小是否为一个字节。
我建议在文档中搜索一个更好的解决方案来读取实际文件大小。
答案 1 :(得分:0)
所以我还是不知道为什么File.size?方法没有得到正确的大小,但我发现通过调用系统du <filename>
我每次调用命令时都会得到更新的文件大小。
基本上我正在做的是:
IO.popen("du <filename>").readlines.first
如果此命令返回两次相同的字符串,我知道该文件不再被写入。
如果有人知道如何解决这个问题,我很乐意听到。