473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Compressing a raw file

I had written a c code that can compress a raw file where my requirement is, There should not exist continual repetitions of 3 bytes in a raw file where I have to compress it and decompress it.
Ex: aaaaaabbbbbbccccccccccccbbbbbbbbbbbb is raw input
encoded file should be aaa2bbb2ccc4bbb4 and on decoding I should get same file as it was before. code for compress and decompress is attached.Its working for text file please some one help me the same for Raw file.
Attached Files
File Type: txt encoding.txt (1.1 KB, 309 views)
File Type: txt deoding.txt (1.2 KB, 300 views)
Feb 13 '14 #1
9 1462
donbock
2,426 Expert 2GB
What if the original file was "aaa2bbb2ccc4bbb4" -- how will you determine that decompression is not needed in this case but it is needed in your original example?
Feb 13 '14 #2
Thank you for the quick response.And my given file is a raw file and its enough if it gets compressed.Whatever may be the pattern my end application is concentrated on just compressing and decompressing given raw file in above mentioned format
Feb 14 '14 #3
donbock
2,426 Expert 2GB
Did you invent this compression/decompression algorithm or was it specified for you?

Your original post gave an example of a text file, both original and compressed. Please give a similar example of what you expect for a raw file.
Feb 14 '14 #4
Actually I took example to make sure one understand what has to be done and criteria.and ya seeing the requirement I decided this would be most probably the suitable one.And my actual criteria is just read 3 bytes from a raw file and see that the 3 bytes pattern won't repeat continually. Ex .R24 format file. For text file the same one which I ve attached would work. But for raw data file some readings are not getting proper so thought if a post some one would help.
Feb 15 '14 #5
Please some one throw light towards it.If at all any changes to be considered while editing or reading a raw file do inform.
Feb 24 '14 #6
donbock
2,426 Expert 2GB
I assume you mean "binary file" when you say "raw file".
I don't understand your compression algorithm. Please indicate the desired encoded file for the following 12-byte unencoded binary file:
0x01 0x01 0x01 0x01 0x01 0x03 0x03 0x04 0x04 0x04 0x05 0x06
Feb 24 '14 #7
What ever pattern consider 3 bytes should not repeat ex:abcabcabc021369/*-/*-****** to be encoded as abc030210136901/*-02***02
(Given I ve considerd ex of this only to understand the encoded format.In actual file all characters in extended ascii)
Feb 25 '14 #8
♀A╘b╝╝╝.₧B╝▐▐▐▐▐▐▐*╧****■■■■■■■■■■^■■■■ this is how the content look like in the given raw file
Feb 25 '14 #9
donbock
2,426 Expert 2GB
I'm afraid I don't understand how this compression algorithm works. So I'll just give you some general comments on your code...

encoding.txt
  • Should the output file be opened as a binary file?
  • You don't check if fread returns a value smaller than 3.
  • You use strcpy and strcmp, but a binary file might contain a data value of zero, which would be mistaken for a terminating null.
  • Near the bottom is "if(ctr <= f)". Where is f defined?
  • Right after that is "fprintf(tfp,"%x",0);" This puts a binary zero (not '0') in the file. Is that what you want to do?
  • At the top of your loop you use fwrite, at the bottom you use fprintf. Shouldn't they all be fwrite?
deoding.txt
  • Probably should open both files for binary access.
  • You should check if fread returned fewer characters than you asked for.
  • This function expects the repetition count to be two decimal-ASCII characters. I see nothing in encoding.txt to prevent the count from being more than two characters.
Feb 25 '14 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: J Poirier | last post by:
Hi All, I'm hoping that someone might have some pointers or examples on how to proceed with a solution to the following problem: A test application, which produces a trace file, is being run...
8
by: Dennis Hotson | last post by:
Hi, I'm trying to write a function that adds a file-like-object to a compressed tarfile... eg ".tar.gz" or ".tar.bz2" I've had a look at the tarfile module but the append mode doesn't support...
10
by: Dennis Farr | last post by:
It has been suggested that rather than convert an already large flat file, with many similar rows, to XML, some type of header be attached to the file, containing some sort of meta-XML description...
0
by: Yuancai \(Charlie\) Ye | last post by:
Hi, All: I am happy to annouce that we have formally released our latest SocketPro version 4 at www.udaparts.com, an advanced remoting framework written from batching/queue, asynchrony and...
1
by: john smith | last post by:
Hi, In my .NET application I save data in an XML file. When opening a project from an XML file I parse the file and recreate objects, set settings etc. The problem is that the XML file can be...
8
by: siliconwafer | last post by:
Hi All, If I open a binary file in text mode and use text functions to read it then will I be reading numbers as characters or actual values? What if I open a text file and read it using binary...
4
by: ad | last post by:
I want to send a DataSet to WebService, but the DataSet if too huge(there about 50000 records, and 50 fields every record). My solution is 1.save the DataSet as XML file, 2.zip the XML file. 3....
7
by: Mark | last post by:
Good evening all, using a XP pro platform and Access 2003 SP2, is it possible to identify a .zip file, inflate the file and then import the contents? I'm pretty certain I could code steps 1 & 3...
3
by: msankardas | last post by:
Hi, As a part of my project, i need to compress folders and files into a single zip file as follows. for eg: I want to compress C:\test\ c:\compression\ C:\documents\test.txt
0
by: Charp | last post by:
I have an application that saves data to a MS Access database and then compresses it. The annoyance here is that I get a double extension on my zip folder. (*.accdb.gz). I have come up with an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.