ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I created tar file inside buffer by using libarchive API.
archive_write_open_memory(file_handle->a,file_handle->buf,1024,&file_handle->used);
File will be created inside file_handle->buf
Now i want to read data from this buffer in place of file.
For example for read data from tar file we can call read system call by passing fd.
How we can achieve same reading through buffer?
You should follow the suggestion you received in your other thread, Creating tar in buffer through libarchive and streaming it, and review information about how to use the Linux Questions site as well as how to ask effective questions.
Glad you feel you've succeeded with creating the buffer. Now you're saying you wish to read the buffer. Either this buffer is in memory, or it is a file. Do you know how to reference and read memory using the C language? Do you know how to open and read a file using the C language? Either case, these are the items you'd need to do to read information. It's rather hard to give you an exact statement how to do something when it is unclear what you've tried, and what your programming experience is.
Hi,
Its not a simple buffer reading, the buffer will be containing tar data so how to do tar reading from buffer.
Buffer i am refering to inmemory not file
Simple buffer reading will not work since it is a tar stream.
Normal buffer reading will not work since it conatin tar stream.
But if we do read system call from file it works as expected but read need a fd and use for file reading.
aside from what the api doing it, buffer is just a memory slot with data in it, like opening a file and putting it contents into a buffer then acting on it. I'd think this to be similar.
archive_read_open_memory this will again create archieve after reading from buffer.I dont want this i want data to be copied to normal char * buffer that can flush.If you will archieve buffer as normal buffer it will give incalid result
char buff[1024];//temp buffer for reading from file.
char archive_buf[2048]//archive will be store in this buffer.
int used ;
a = archive_write_new();
archive_write_add_filter_gzip(a);
archive_write_set_format_pax_restricted(a); // Note 1
archive_write_open_memory(a,archive_buf,1024,&used);
stat(*filename, &st);
entry = archive_entry_new();
archive_entry_set_pathname(entry, "sample.xml");
archive_entry_set_size(entry, st.st_size);
archive_entry_set_filetype(entry, AE_IFREG);
archive_entry_set_perm(entry, 0644);
archive_write_header(a, entry);
fd = open("sample.xml", O_RDONLY);//opening xml file and reading its content so that tar can be prepared.
len = read(fd, buff, sizeof(buff));
while ( len > 0 ) {
len = read(fd, buff, sizeof(buff));
archive_write_data(a, buff, len);
}
Creation of archive in buffer is done.
Now how to do reading from this buffer and send it as MIME to Server?
If I have tar as file below method is working as expected.
bytes_read = fread(buf_containing_read_bytes_from_tar_file, sizeof(char), 1024, (FILE*)file pointer to tar file);
Same thing how i can do when data is in buffer??//Note I cannot use buf which i used for creating archive.It is just a place holder.I need to read data from this buffer and write data into streaming buffer.
Last edited by astrogeek; 01-18-2019 at 02:13 PM.
Reason: Added CODE tags
Please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.
I have fixed that in your previous post as an example.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.