英文:
Is it possible to fingerprint a file agnostic of it's type?
问题
可以通过编程的方式向文件添加指纹吗?这个指纹可以适用于任何文件类型吗?我正在尝试追踪泄漏问题,想知道是否可以像下面的代码一样对任何类型的文件进行指纹标记。
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
panic(err)
}
defer f.Close()
if _, err = f.WriteString(text); err != nil {
panic(err)
}
英文:
Is it possible to add a fingerprint to a file programmatically that works on every filetype? I'm trying to track down leaks and am wondering if doing something like the following to fingerprint any file completely agnostic of the type.
if err != nil {
panic(err)
}
defer f.Close()
if _, err = f.WriteString(text); err != nil {
panic(err)
}
</details>
# 答案1
**得分**: 2
可以通过编程将指纹添加到每种文件类型吗?
不可以。许多文件是不可写的,你无法添加任何内容。即使对于可写的文件,这也不是通用的方法(例如/dev/null)。
<details>
<summary>英文:</summary>
> Is it possible to add a fingerprint to a file programmatically that works on every filetype?
No. Lots of files are not writable and you cannot add nothing. Even along those which are writable this doesn't work in general (e.g. /dev/null).
</details>
# 答案2
**得分**: 1
一些文件系统支持任意元数据。也许这是一种添加额外信息(如校验和)的好方法。
https://unix.stackexchange.com/questions/290151/what-does-mounting-a-filesystem-with-user-xattr-do
然而,如果将文件移动到另一个文件系统,可能会丢失这些信息。
甚至有一个Go库
https://github.com/davecheney/xattr
<details>
<summary>英文:</summary>
Some filesystems support arbitrary metadata. Perhaps it is a good way to add extra info like the checksum.
https://unix.stackexchange.com/questions/290151/what-does-mounting-a-filesystem-with-user-xattr-do
However, you may lost such information if you move the file to another filesystem.
There is even a go library
https://github.com/davecheney/xattr
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论