|
Update...
The .gz appears fine; I was able to extract it using WinZip (224 MB -> 877 MB). I tested Ionic's version of GZipStream, and it also resulted in a 24K file, along with the following error message:
Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
Here is the Ionic-GZipStream version (which is almost identical to the previous):
private static void gDecompressIonic(FileInfo file)
{
using (FileStream inFile = file.OpenRead())
{
string curFile = file.FullName;
string origName = curFile.Remove(curFile.Length - file.Extension.Length);
using (FileStream outFile = File.Create(origName))
{
using (Ionic.Zlib.GZipStream Decompress = new Ionic.Zlib.GZipStream(inFile, Ionic.Zlib.CompressionMode.Decompress))
{
byte[] buffer = new byte[4096];
int numRead;
while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
{
outFile.Write(buffer, 0, numRead);
}
}
}
}
}
|
|
|
|
|
Timothy CIAN wrote: The .gz appears fine; I was able to extract it using WinZip
Maybe the creator is using winzip rather than a gzip library. And winzip itself is doing something odd.
Did you try a straight gzip utility?
|
|
|
|
|
Does the file use Deflate64?
WinZip handles that, but almost nothing else does.
|
|
|
|
|
FWIW: I just finished a WinZip-like (but incompatible) utility based on System.IO.Compression.GZipStream and it perfectly decompresses files it compressed before, whatever the file size is (tried up to 2MB). Typical compression ratio is about 3 except of course for PDF, JPEG, and very small files.
|
|
|
|
|
we have implemented the Compression/Decompression in C# using J# APIs. This J# supported in .Net 2.0 but MS have removed the support for J# in .Net4.0.
we are migrating to .Net 4.0 and need to rewrite J# implementation in C# as J# is no longer supported.
We tried using GZipSteam/ZipPackage but that do not provide the backward compatiblity i.e, we cannot use J# compressed file for decompressing. Also multiple file compression using GZipSteam is complex.
Is there any other solution to do compression/decompression in C# itself.(We do not want to use third party library). Is is possible to write compression/decompression algorithm in C#?
Any suggessions are welcome.
|
|
|
|
|
Yes - if you know what the algorithm J# used is. (I don't)
But an easier solution (if a bit clunky) would be to create a J# standalone module in .NET 2 and call into that from your C#.
It means you have some code base you can't alter easily, but it would ensure that you could read your existing files. You could then automatically migrate them to Zip as you come across them, so eventually the J# stuff has disappeared.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thanks for your infomation.
I am thinking whether we can create a module in Java that takes care of comp/decomp.
We can make use of that JAVA module in C# via interface methods. Is that would be possible?
|
|
|
|
|
Hi my freinds,
Happy new year 2012 First.
I develop some websites with .NET technologie. I want to automatise my tests. I search on the internet for test tools. i find many (NEOTYS, QF-test, NUNIT...). But i don't know what is the most performant tool. In fact, i have some rules in my deveopement (for example, in my interfaces, all textFields should be align , numbers should be rigth align...). I want to use a tool that has double function : test, network and code test.
If u have prepositions , plzzzzz tell me about I am really needing this in my work.
Regards
|
|
|
|
|
Hi,
When I try...
people.OrderBy(name => name.Name);
I get...
ex = {"An order by expression can only contain non-constant scalars that are order comparable by the server. The expression with type 'Text' is not order comparable."}
Can I get IEnumerable OrderBy to sort on a text field, using a predicate perhaps?
Thanks.
|
|
|
|
|
There must be some mistake in your code prior to your orderby call, as you should be able to order by text. As a quick demo I did this
public partial class Form1 : Form
{
List<Person> sortedPeople;
public Form1()
{
InitializeComponent();
List<Person> people = new List<Person> {new Person("wayne"), new Person("sarah"), new Person("mark"), new Person("simon"), new Person("ashleigh"), new Person("dave"), new Person("connor"), new Person("bronwyn"), new Person("chantelle"), new Person("will"), new Person("chris")};
sortedPeople = people.OrderBy(name = name.Name).ToList();
}
}
class Person
{
public Person(string name)
{
this.Name = name;
}
public string Name { get; set; }
}
and SortedPeople came out correctly
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Hi,
try the below code snippet
var newList = people.OrderBy(name => name.Name).ToList();
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
Hi, thanks for looking at this.
Not sure what I am doing wrong.
I tried...
DataContext = new DataClasses1DataContext();
var people = from name in DataContext.Table_Peoples
where name.IQ < 3
select name;
var peopleOrdered = people.OrderBy(name => name.Name).ToList();
'Name' is decared as follows...
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="Text", UpdateCheck=UpdateCheck.Never)]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this._Name = value;
}
}
}
It is still thowing the same exception.
|
|
|
|
|
Ok I got it to work like this...
DataContext = new DataClasses1DataContext();
var people = from name in DataContext.Table_Peoples
where name.IQ < 3
select name;
List<Table_People> listPeople = people.ToList();
var peopleOrdered = listPeople.OrderBy(name => name.Name).ToList();
But I dont understand why I have to copy to a List first?
|
|
|
|
|
Quote: __John_ wrote: List<Table_People> listPeople = people.ToList();
var peopleOrdered = listPeople.OrderBy(name => name.Name).ToList();
To order the list, it requires the set of names to be in a format and we are storing it as the enumerable list.
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
Hi Manognya,
I dont understand why List.OrderBy works when IEnumerable.OrderBy does not?
I am not sure what you mean when you say 'in a format'?
Thanks.
|
|
|
|
|
Hi John,
The syntax of OrderBy is:
Public Shared Function OrderBy(Of TSource, TKey) ( _
source As IEnumerable(Of TSource), _
keySelector As Func(Of TSource, TKey) _
) As IOrderedEnumerable(Of TSource)
Parameters
source
Type: System.Collections.Generic.IEnumerable(Of TSource)
A sequence of values to order.
keySelector
Type: System.Func(Of TSource, TKey)
A function to extract a key from an element.
we need to convert the source to be of type
System.Collections.Generic.IEnumerable
Hope this helps.
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
|
Thanks, it is slowly becoming clear, I probably just need to think about it a bit more.
I do sometimes find templates a bit confusing.
+5
|
|
|
|
|
Agree..templates is always little tricky(for me either )...But, Once got..makes life easy
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
The difference is not the IEnumerable or the List but where the OrderBy take place.
When you call ToList,or any greedy query operators, you execute your Ling query against your DB. After that, all Linq operation are executed in memory and Linq-to-object can do more things in than Linq-to-sql, or Linq-to-entities
Vince
Remember the dead, fight for the living
|
|
|
|
|
Thanks Vince, that explains it a bit more.
I think i can now understand what the debuger is showing me.
It uses a 'lazy' stratergy, ie. only evaluating an expression or executing a function when the result is actually needed, am I right?
BTW: How can I enumerate the results more that once?
Hoping that is not too stupid a question
Thanks - John.
|
|
|
|
|
|
__John_ wrote:
It uses a 'lazy' strategy, ie. only evaluating an expression or executing a function when the result is actually needed, am I right?
Yes you are right. It's a principle of Linq to defer execution until is needed. And Linq also evaluate only the elements needed to return the result
Let's take Wayne List and do some examples
List<Person> peoples = new List<Person> {new Person("wayne"), new Person("sarah"), new Person("mark"), new Person("simon"), new Person("ashleigh"), new Person("dave"), new Person("connor"), new Person("bronwyn"), new Person("chantelle"), new Person("will"), new Person("chris")};
int Count = people.Count(p => p.Name.StartsWith("w"));
var firstperson = people.Where(p => p.Name.Length == 5).Take(3);
foreach (var p in firstperson)
{
Console.WriteLine(p.Name);
}
var firstperson2 = people.Where(p => p.Name.Length == 5).Take(3);
people.Insert(1, new Person("Vince"));
foreach (var p in firstperson)
{
Console.WriteLine(p.Name);
}
http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx[^]
__John_ wrote: BTW: How can I enumerate the results more that once?
If you use a Enumerator<t>, you can use Reset to set the enumerator to its initial position, which is before the first element in the collection.
But if you use a foreach loop, you can reuse an Enumerable<t> many times. The foreach loop will start at the beginning every time.
Vince
Remember the dead, fight for the living
|
|
|
|
|
|
Nice examples - thanks!
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|