如何跳过tar文件中的文件以获取特定文件 [英] how to skip a file inside the tar file to get a particular file
问题描述
我正在获取一个html文件的内容,它存在于tar文件中(我使用可视化c ++来完成我的任务)。我的方法是使用流存储tar在缓冲区中,然后将html的内容存储在另一个缓冲区。然后使用缓冲区转到tar文件中的每个文件的文件名在位置缓冲区[0-100](在此位置我们有文件名),并将文件名存储在内容(在我的情况下),并搜索是否有extension.html文件?
i am tring to get the contents of a html file which is present inside the tar file(i am using visual c++ to accomplish my task). my approach is to store the tar in a buffer using a stream and then store the contents of html in another buffer.Then using buffer going to the file name of each file present in tar file at location buffer[0-100](at this location we have the file name)and store the file name in "contents"(in my case) and search if it has the extension.html file ??
如果它在文件名中有.html,然后从位置缓冲区存储它的内容[PreviousFileSizes +512](通过PreviousFileSizes我的意思是在这之前有一些文件html文件,所以我们必须添加他们的大小在缓冲区索引去到正确的位置 - 我的意思是我不是假设tar文件中的第一个文件是html文件 - 在我的代码中我表示这个PreviousFileSizes通过跳过表示这个大小跳过去我们的html文件)。
If it has .html in the name of the file then store its contents from the location buffer[PreviousFileSizes +512](by PreviousFileSizes i mean there were some files before this html file so we have to add their sizes in the buffer index to go to the correct location- i mean i am not assuming that the first file in tar file is html file-In my code i denote this PreviousFileSizes by "skip" - that means this much size to skip to go to our html file).
我的代码实现它是 -
my code to achieve it is-
int skip=0;
char contents [100];
//char test[1000];
do
{
int SizeOfFile = CreateOctalToInteger(&buffer[skip+124],11);
size_t distance= ((SizeOfFile%512) ? SizeOfFile + 512 - (SizeOfFile%512) : SizeOfFile );
size_t skip= distance +512;
memcpy(contents,&buffer[skip],100);
}
while(strstr(contents,".html") != NULL);
我会走错吗?如果我的逻辑有什么问题, p>
am i going right ??Please correct me if there is anything wrong in my logic ??
推荐答案
最后我已经为这个问题的解决方案,代码必须如下 -
Finally i have made the solution for this question the code must be as follow-
char* StartPosition;
size_t skip= 0;
char HtmlFileContents [200000];
char contents [8000];
do
{
int SizeOfFile = CreateOctalToInteger(&buffer[skip+124],11);
size_t distance= ((SizeOfFile%512) ? SizeOfFile + 512 - (SizeOfFile%512) : SizeOfFile );
skip += distance + 512;
memcpy(contents,&buffer[skip],100);
if (StartPosition=strstr(contents,".html"))
{
MessageBox(m_hwndPreview,L"finally string is copied",L"BTN WND6",MB_ICONINFORMATION);
int SizeOfFile = CreateOctalToInteger(&buffer[skip+124],11);
memcpy(HtmlFileContents,&buffer[skip+512],SizeOfFile);
break;
}
}
while(strcmp(contents,".html") != NULL);
我猜它的自我解释。如果不 ??不要犹豫,问我。
I guess its self explantory . and If not ?? Do not hesitate to ask me.
这篇关于如何跳过tar文件中的文件以获取特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!