Click here to Skip to main content
16,005,473 members
Home / Discussions / C#
   

C#

 
AnswerRe: Why is my regex cutting of last char when doing replace? Pin
Luc Pattyn8-Feb-12 12:07
sitebuilderLuc Pattyn8-Feb-12 12:07 
AnswerRe: Why is my regex cutting of last char when doing replace? Pin
Bernhard Hiller8-Feb-12 20:51
Bernhard Hiller8-Feb-12 20:51 
QuestionAnybody familiar with compression? (Using it I mean) Pin
SledgeHammer018-Feb-12 8:21
SledgeHammer018-Feb-12 8:21 
AnswerRe: Anybody familiar with compression? (Using it I mean) Pin
Luc Pattyn8-Feb-12 8:28
sitebuilderLuc Pattyn8-Feb-12 8:28 
GeneralRe: Anybody familiar with compression? (Using it I mean) Pin
SledgeHammer018-Feb-12 9:53
SledgeHammer018-Feb-12 9:53 
AnswerRe: Anybody familiar with compression? (Using it I mean) Pin
Luc Pattyn8-Feb-12 10:04
sitebuilderLuc Pattyn8-Feb-12 10:04 
GeneralRe: Anybody familiar with compression? (Using it I mean) Pin
harold aptroot8-Feb-12 10:13
harold aptroot8-Feb-12 10:13 
GeneralRe: Anybody familiar with compression? (Using it I mean) Pin
SledgeHammer018-Feb-12 11:52
SledgeHammer018-Feb-12 11:52 
Luc Pattyn wrote:
I have never met a compressor that does that; in apps such as 7zip and WinZip,
each file is compressed individually, and can be extracted on its own, even
after deleting some or all of the others.


So I'm kind of assuming that if I can compress 400 .js files into a single .7z archive, that compressing 400 .js files into 400 .7z files should be roughly the same size?

Luc Pattyn wrote:
How do you compress that? which classes and/or algorithms are involved?


I downloaded the SDK from here http://www.7-zip.org/sdk.html[^], the 9.22 version. I'm using the native C# version. This is the code I'm using to compress the text blocks.

C#
foreach (SoftDataSet.tblScriptRow row in ds.tblScript.Rows)
{
                int i = row.Text.Length;
                a += i;

                System.Diagnostics.Debug.WriteLine("BEFORE: " + row.Text.Length);


                SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();

                SevenZip.CoderPropID[] propIDs = 
				{
					SevenZip.CoderPropID.DictionarySize,
					SevenZip.CoderPropID.PosStateBits,
					SevenZip.CoderPropID.LitContextBits,
					SevenZip.CoderPropID.LitPosBits,
					SevenZip.CoderPropID.Algorithm,
					SevenZip.CoderPropID.NumFastBytes,
					SevenZip.CoderPropID.MatchFinder,
					SevenZip.CoderPropID.EndMarker
				};

                Int32 dictionary = 0x00800000;
                Int32 posStateBits = 2;
                Int32 litContextBits = 3; // for normal files
                Int32 litPosBits = 0;
                Int32 algorithm = 2;
                Int32 numFastBytes = 128;
                string mf = "bt4";
                bool eos = false;

                object[] properties = 
				{
					(Int32)(dictionary),
					(Int32)(posStateBits),
					(Int32)(litContextBits),
					(Int32)(litPosBits),
					(Int32)(algorithm),
					(Int32)(numFastBytes),
					mf,
					eos
				};

                encoder.SetCoderProperties(propIDs, properties);


                MemoryStream ms = new MemoryStream(row.Text);
                MemoryStream msOut = new MemoryStream();

                encoder.WriteCoderProperties(msOut);
                encoder.Code(ms, msOut, -1, -1, null);

                System.Diagnostics.Debug.WriteLine("AFTER: " + msOut.Position + " " + (msOut.Position) * 100 / i + "%");
                b += (int)msOut.Position;
            }

            System.Diagnostics.Debug.WriteLine("1: " + a + " 2: " + b);
}


If I use the above code to compress the 4.5MB single file, it does get down to 200k like the real 7zip app.

But with the above code doing each row by itself... 1: 4551167 2: 885162

So, somehow its getting 685k of extra crap or???

EDIT: FYI, writing out the properties to the output stream is only 5 bytes. So that only accounts for about 2k.
AnswerRe: Anybody familiar with compression? (Using it I mean) Pin
Luc Pattyn8-Feb-12 12:12
sitebuilderLuc Pattyn8-Feb-12 12:12 
GeneralRe: Anybody familiar with compression? (Using it I mean) Pin
SledgeHammer018-Feb-12 13:08
SledgeHammer018-Feb-12 13:08 
GeneralRe: Anybody familiar with compression? (Using it I mean) Pin
SledgeHammer018-Feb-12 13:56
SledgeHammer018-Feb-12 13:56 
AnswerRe: Anybody familiar with compression? (Using it I mean) Pin
Luc Pattyn9-Feb-12 4:33
sitebuilderLuc Pattyn9-Feb-12 4:33 
AnswerRe: Anybody familiar with compression? (Using it I mean) Pin
Luc Pattyn8-Feb-12 10:39
sitebuilderLuc Pattyn8-Feb-12 10:39 
QuestionUsing Controls in multiple threads Pin
Danzy838-Feb-12 7:47
Danzy838-Feb-12 7:47 
AnswerRe: Using Controls in multiple threads Pin
Luc Pattyn8-Feb-12 8:21
sitebuilderLuc Pattyn8-Feb-12 8:21 
AnswerRe: Using Controls in multiple threads Pin
DaveyM698-Feb-12 8:43
professionalDaveyM698-Feb-12 8:43 
QuestionThe type or namespace name 'Excel' could not be found Pin
pmcm8-Feb-12 5:17
pmcm8-Feb-12 5:17 
AnswerRe: The type or namespace name 'Excel' could not be found Pin
Wes Aday8-Feb-12 5:24
professionalWes Aday8-Feb-12 5:24 
GeneralRe: The type or namespace name 'Excel' could not be found Pin
pmcm8-Feb-12 5:31
pmcm8-Feb-12 5:31 
GeneralRe: The type or namespace name 'Excel' could not be found Pin
Richard MacCutchan8-Feb-12 6:25
mveRichard MacCutchan8-Feb-12 6:25 
AnswerRe: The type or namespace name 'Excel' could not be found Pin
Eddy Vluggen8-Feb-12 9:12
professionalEddy Vluggen8-Feb-12 9:12 
GeneralRe: The type or namespace name 'Excel' could not be found Pin
Richard MacCutchan8-Feb-12 21:41
mveRichard MacCutchan8-Feb-12 21:41 
AnswerRe: The type or namespace name 'Excel' could not be found Pin
Eddy Vluggen9-Feb-12 0:17
professionalEddy Vluggen9-Feb-12 0:17 
GeneralRe: The type or namespace name 'Excel' could not be found Pin
Richard MacCutchan9-Feb-12 0:58
mveRichard MacCutchan9-Feb-12 0:58 
AnswerRe: The type or namespace name 'Excel' could not be found Pin
Eddy Vluggen9-Feb-12 4:59
professionalEddy Vluggen9-Feb-12 4:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.