如何安全地删除文件?
是否有 Gem 或方法可以安全地删除 Ruby 中的文件?我想避免系统上可能不存在的外部程序。
我所说的“安全擦除”是指覆盖文件内容。
Is there a Gem or means of securely erasing a file in Ruby? I'd like to avoid external programs that may not be present on the system.
By "secure erase" I'm referring to overwriting the file contents.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 *nix,一个很好的方法是使用 exec/open3/open4 调用 shred
: .html" rel="nofollow noreferrer">http://www.gnu.org/s/coreutils/manual/html_node/shred-in Vocation.html
检查这个类似的帖子:
用 python 或 ruby 编写文件粉碎机?
If you are on *nix, a pretty good way would be to just call shred using exec/open3/open4:
http://www.gnu.org/s/coreutils/manual/html_node/shred-invocation.html
Check this similar post:
Writing a file shredder in python or ruby?
像这样的事情会帮助你开始:
它应该会让你接近。
为了更彻底,您还可以使用
0xaa
和0x55
来交替字节中的 0 和 1 位。Random.rand(0xff)
将为您提供 0 到 255 之间的随机值。Something like this will get you started:
It should get you close.
For more thoroughness, you could also use
0xaa
and0x55
for alternating 0 and 1 bits in the byte.Random.rand(0xff)
will give you a random value from 0 to 255.只需
flush()
和close()
just
flush()
andclose()
0xff
's on different passes