NUL字符是解压缩的git对象文件中的什么?

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

What is NUL character in unzipped git object files?

问题

我尝试解压缩.git/objects中的提交/数据块文件。我使用zlib和nodeJS来完成这个任务。

解压缩后,例如index.html数据块的结果如下:

NUL字符是解压缩的git对象文件中的什么?

问:这个NUL字符是什么意思?在解压缩时,我是否做错了什么?

英文:

I try to unzip .git/objects' commit/blob files. I do it using zlib and nodeJS.

The result after unzipping e.g. index.html blob is ▼

NUL字符是解压缩的git对象文件中的什么?

NUL字符是解压缩的git对象文件中的什么?

Question: what this NUL character means? Am I doing something wrong while unzipping?

答案1

得分: 1

这是一个字节,其序数值为0。NUL字节通常有四个常见用途:在C编程上下文中,它们用作字符串的结尾终止符(NUL终止字符串)。

在文本文件中,它们通常用于分隔数据字段。在二进制数据文件中,它们通常只是数据的一部分。

它们还用于填充文件中的数据以确保特定的对齐方式。例如,为了使二进制文件中的32位整数对齐到4字节,以便可以轻松读取和处理。

英文:

It's a byte of ordinal value 0. NUL bytes serve 4 usual purposes: In the context of programming with C they are the end-of-string terminator (NUL terminated string).

In files with text they're normally used to delimit fields of data. In files with binary data, they're usually just part of the data.

And they're used for padding data inside files to certain alignment. So for example to make it that 32 bit integers inside a binary file are aligned to 4 bytes, so that they can be trivially read and processed.

答案2

得分: 1

在这种情况下,NUL 终止了字符串 blob 14。根据Git 内部结构的描述

> Git 首先构造一个头部,其中首先标识对象的类型 — 在这种情况下是一个 blob。在头部的第一部分,Git 添加一个空格,然后是内容的字节大小,最后添加一个空字节。

英文:

In this case the NUL is terminating the string blob 14. From a description of the git internals:

> Git first constructs a header which starts by identifying the type of
> object — in this case, a blob. To that first part of the header, Git
> adds a space followed by the size in bytes of the content, and adding
> a final null byte

huangapple
  • 本文由 发表于 2023年2月16日 15:52:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75469251.html
匿名

发表评论

匿名网友

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

确定