是否可能对文件进行指纹识别而不考虑其类型?

huangapple go评论70阅读模式
英文:

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>

&gt; 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&#39;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>



huangapple
  • 本文由 发表于 2022年3月31日 01:09:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/71681379.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定