I'm using Curl to download files from the internet. If a file is big, through the use of the Range header i split it in 3 chunks and i download them separately making multiple connection to the same url. Now the problem is, how do i join back those 3 different chunks into one big file? Searching on the internet all i found is merging text files using fgetc, fgets and the likes which interpret the data as text files. But my files are mostly video files or big iso files hence binary data. I looked into fwrite but how can i know which size is one element? It's just binary data. I'm confused.
The Curl routine which writes to the various chunks is this:
size_t write_data(void *ptr, size_t sz, size_t nmemb, FILE *stream) { size_t written = fwrite(ptr, sz, nmemb, stream); return written; }
Let's say i downloaded these 3 chunks, filepath1.x, filepath2.x, filepath3.x, how can i merge them into output.mp4?
Joining or merging files in C
73 Views Asked by amateur At
1
There are 1 best solutions below
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in FILE
- Helpt with reading files
- Why can't I use the file pointer after the first read attempt fails?
- Can't read the file using std::wifstream C++
- How can the scanner reread the entire file after it has already executed hasNextLine once?
- What is 'Invalid Load Key, '\x00'
- php $_FILE variable undefined index
- Data loaded from the file is not returned in the correct order
- File splitting and encryption
- Optimizing an s5cmd command that uses awk to generate a text file
- segmentation fault while reading in text file ( c++ )
- File.OpenText is adding C:\ to the front which is an error
- UTF-8 issue with excel
- How to upload files to MediaWiki APIs in Rust?
- No such file or directory: '/tmp/tmp_ejr26m6.upload.mp3' in Django
- Problems accessing zip files on the react front end from express backend
Related Questions in JOIN
- Hibernate: JOIN inheritance question - why the need for two left joins
- PHP fetchAll on JOIN
- Polars asof join on next available date
- Merge effective dated records of an attribute with the main effective dated table (SQL)
- Repeat Value for Every Instance of Another Value in Excel without using Power Query
- Is it correct to add "UNNEST" in the "ON" condition of a (left) join?
- Is there a way in Laravel to use multiple connections simultaneously in a combined manner?
- How can I join data to my table that isn't available for everyone without losing results?
- Using max/min on columns with null values
- Qlik IntervalMatch to SQL
- Join two tables by columnname when columnames for joining stored in a table
- Combining two dataframes with different column name in time-series
- How to deal with complex oracle sql query in spring boot?
- Join data frames with multiple conditions
- PySpark: NULL values in Join 2nd dataframe should match
Related Questions in MERGE
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- Having trouble merging these two datasets for a Spatial Analysis
- Merge Azure mp4 blobs via API (Preferred Azure)
- Git merge strategies vs. merge drivers vs. mergetools
- Merge Request in Bitbucket: Possible to exempt a specific branch to ask for Merge Request?
- How to properly extend the generic interface with a new generic parametr using decration merging in Typescript?
- Merge effective dated records of an attribute with the main effective dated table (SQL)
- How do I merge multiple tables into a new table in BigQuery?
- Exclude a file from merging to the main branch
- Usage of merge in linux sort utility
- How can I collapse repeated missing observations into a single nonmissing observation for the same ID in SAS?
- Best way to automate auto-merging git branches
- git: merging a branch that's already been merged by mistake
- Dynamically create, merge & save dataframes in a for loop
- VBA find matching Excel files with a subtext - and merge them into single new file
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Since you're using shell utilities anyway, the trivial way to do this is with
cat.cat file1.x file2.x file3.x > file.x.If you want to do this in pure C, use
fopenbut switched to read binary files. Text vs binary is only an issue on Windows. POSIX systems (Unix and MacOS) don't make a distinction.If this is just a little utility program, print to stdout and use shell piping to redirect the output to a file. Just like
cat.We read each file by allocating a fixed buffer, and reading and writing chunks into and out of that buffer. I like to use the
BUFSIZconstant because that's likely to be the same as the block size of your system which makes reading more efficient. 4096 is also a good value, 4k is a common block size.freadandfwriteare odd. Rather than just telling them how much to read, we need to tell them to read X number of Y sized objects. This is a hold over from record-oriented filesystems and most useful when you're reading a list of fixed sized objects. Since a C string is an array of 1 byte characters, we want to read 1 byte N times. Asking to read up to the size of our buffer is:fread(buf, 1, sizeof(buf), f).freadreturns the number of objects read. We're reading 1 byte objects, so this is equivalent to the number of bytes. We write that amount tofwrite. If BUFSIZ is 4096 bytes but the file is only 50 bytes we'll only write 50 bytes, not 50 bytes plus 4046 bytes of trash.