Archive

Posts Tagged ‘csharp’

Uncompressing UNIX *.Z files

December 6th, 2009 8 comments

I searched online for a .NET library that can be used to decompress *.Z files (compressed by the UNIX compress utility) but was unable to find anything non-commercial. I found however some code in Java that looked promising, so I ported it to C#. I integrated the resulting code with the SharpZipLib library, but until that gets officially integrated and released, I decided to release a stand-alone version here.

The code is contained in a single file (download LzwInputStream.cs) and is pretty straight-forward to use. The following example shows how to uncompress a *.Z file using c-sharp.

using System;
using System.IO;

using Ebixio.LZW;

class MainClass
{
    public static void Main(string[] args)
    {
        byte[] buffer = new byte[4096];
        string outFile = Path.GetFileNameWithoutExtension(args[0]);

        using (Stream inStream = new LzwInputStream(File.OpenRead(args[0])))
        using (FileStream outStream = File.Create(outFile)) {
            int read;
            while ((read = inStream.Read(buffer, 0, buffer.Length)) > 0) {
                outStream.Write(buffer, 0, read);
            }
        }
    }
}

Vim syntax for xaml files

September 20th, 2009 2 comments

So you’re using Windows and want to edit your xaml files every once in a while with vi/vim/gvim, but vim doesn’t recognize xaml as an xml file and doesn’t give you nice syntax highlighting? Simple fix. In your home directory, create a vimfiles/ftdetect/myrules.vim file with the following contents:

" We set the type to XML only if no type was detected yet au BufRead,BufNewFile *.xaml setfiletype xml " OR unconditionally "au BufRead,BufNewFile *.xaml set filetype=xml
Categories: Uncategorized Tags: , ,