[英]Get magic number from git packfile index in Haskell
I'm wanting to get the magic number from a git packfile index to ensure that it is indeed a packfile. 我想从git packfile索引中获取神奇的数字,以确保它确实是一个packfile。 The pack format documentation states that the magic number is "/377tOc".
包格式文档指出幻数是“/ 377tOc”。 When I open the packfile with Ruby for example, I get this back when reading the file:
例如,当我用Ruby打开packfile时,我在阅读文件时得到了这个:
> File.open("pack-4412d2306cfe9a0b6d1b9b4430abc767022e8a3c.idx").read(4)
=> "\377tOc"
But in Haskell I get this: 但是在Haskell我得到了这个:
> h <- openFile "pack-4412d2306cfe9a0b6d1b9b4430abc767022e8a3c.idx" ReadMode
> Data.ByteString.hGet h 4
=> "\255tOc"
I take it I'm missing something obvious, but it's not clear to me what that is. 我认为我错过了一些明显的东西,但我不清楚这是什么。 What am I doing wrong here?
我在这做错了什么?
The non-ascii character ('\\255') is just being shown in decimal, not octal. 非ascii字符('\\ 255')只是以十进制显示,而不是八进制。
Confirming, according to od
the first 4 bytes are indeed, in octal/ascii or 1 byte decimal: 根据
od
确认前4个字节确实是八进制/ ascii或1字节十进制:
> $ od -c foo.idx | head -1
0000000 377 t O c \0 \0 \0 002 \0 \0 002 250 \0 \0 005 B
> $ od -t u1 /tmp/x | head -1
0000000 255 116 79 99 0 0 0 2 0 0 2 168 0 0 5 66
And in Haskell: 在哈斯克尔:
> s <- Data.ByteString.readFile "foo.idx"
> Data.ByteString.take 4 s
"\255tOc"
So, just remember that 255 in decimal is 377 in octal. 所以,请记住十进制中的255是八进制的377。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.