如何知道焦油解析器里面的文件 [英] How to know the files inside the Tar parser

查看:83
本文介绍了如何知道焦油解析器里面的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Visual C ++应用程序。我需要知道的文件类型(我的意思是它是否包含PNG文件or.html文件或.txt文件)tar文件(只是C ++ prgramming)内$​​ P $ psent什么也没有要处理的命令。
我有链接的一些知识如下─
如何解析一个tar文件
 在这里我有,在缓冲[512]我们有一个文件present的内容里面thge焦油file.My第一quesion是

I am developing a visual c++ application . i need to know the file type (i mean whether it contains .png file or.html file or .txt file) present inside the tar file(just by c++ prgramming)-Nothing to deal with the commands. I have got some knowledge on the link below- how to parse a tar file here i have got information that at buffer[512] we have contents of a file present inside thge tar file.My first quesion is

想,如果我有更多然后1文件present焦油和我从位置尺寸(1)(安培;缓冲区[124],11);从512到文件的大小我有这个文件的conntents,我把它存储在缓冲区对我个人use.But按照我的理解的(内容来自512位置开始),该规则适用于文件present在在tar文件中的第一个位置。如果我要得到这是在3/4位置(如果有什么我不知道有关文件present的tar文件的位置)???

(1.) suppose if i have more then 1 files present in tar and i got the size from the location (&buffer[124], 11); and from 512 to size of the file i had conntents of that file and i stored it in a buffer for my personal use.But as i understand this rule of (contents start from 512 location) is valid for the file present at the first position in the tar file. What if i have to get the position, contents and size of the file which is at 3/4 positions(what if am not sure about the position of the file present in the tar file) ???

(2)我在想合适的?如果我必须去下一个文件的内容我必须做的512 * 2(因为第一个文件的内容开始于512位置,以便下一个文件将在1024是具有我相信它是一个错误的做法,但可以任何一个,请更正? ?)。

(2.) Am i thinking right ??? if i have to go to next file contents i have to do 512*2 (because first file contents starting at 512 location so the next file will be having at 1024- I am sure its a wrong approach but could any one please correct it ??).

其实我有只HTML文件内容存储在从tar文件(其中包含不同类型的文件数)我的缓冲

Actually i have to store only Html file contents in my buffer from the tar file(which contains number of files of different type)

推荐答案

tar文件的内容是永远的报头块数据块头块数据块的......,每一个标题块包含一个文件(文件名,大小,权限,...),后面的数据块的所有信息包含内容的文件。每个数据块的大小的文件大小的512的倍数,因为它是在头块(这句话看起来可怕给我。可以在任何母语是正确的,请)。
所以,如果您已经阅读一个头块,想跳到下一个计算

The contents of a tar file is always header block, data block, header block, data block ... where every header block contains all the information of one file (filename, size, permissions,...) and the following data block contains the contents that file. The size of each data block is the next multiple of 512 of the file size as it is in the header block (that sentence looks awful to me. Could any native speaker correct is please). So if you have read one header block and want to skip to the next one calculate

 size_t skip = filesize % 512 ? filesize + 512 - (filesize % 512) : filesize

,或更performantly

or, more performantly

 size_t skip = filesize + 511 & ~511;

和征求跳过字节着。

例如,如果你的tar文件包含两个文件的 a.bin 的12345尺寸(512倍数是12800)和尺寸123的 b.txt 的(一个倍数512是 - 很明显 - 512),那么你将有:

For example if your tar file contains two files a.bin of size 12345 (next multiple of 512 is 12800) and b.txt of size 123 (next multiple of 512 is -- obviously -- 512) then you would have:


  1. 约含的 a.bin 的信息开始在POS头。 0

  2. a.bin 的数据开始名次。 512

  3. 约含的 b.txt 的信息开始在POS头。 512 + 12800 = 13312

  4. b.txt 的数据开始名次。 13312 + 512 = 13824

  5. tar文件的文件大小将至少13824 + 512 = 14324.在实践中,你会发现一般的tar文件要大一些,在波什的下一个512字节。 14324将 \\ 0

  1. header containing information about a.bin starting at Pos. 0
  2. data of a.bin starting at Pos. 512
  3. header containing information about b.txt starting at Pos. 512 + 12800 = 13312
  4. data of b.txt starting at Pos. 13312 + 512 = 13824
  5. the file size of the tar file will be at least 13824 + 512 = 14324. In practice, you will generally find the tar file to be larger and the next 512 bytes at Pos. 14324 will be \0

这篇关于如何知道焦油解析器里面的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆