Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: XFDL File Decoding

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: Thu, Oct 27, 2011, 9:52 AM


The following C# code will transform an XFDL file (see sample content below) to XML.

Sample Input
application/vnd.xfdl;content-encoding="base64-gzip"
H4sIAAAAAAAAC+y9aZOiyrYw/N1fwdMn4vbeYXfJqLBP776BgooDoOL4xhMdCKgoAjI4xfPj3wS0
RkWtkqoePHHv7hKSHFauOVeu9e1/13MDWmqOq1vmv5+QO/gTpJmKperm+N9PXEv4SpIE9RX59L/f
...

Source Code
using System;
using System.IO;
using System.IO.Compression;

. . .

/*--- Inits ---*/
const string INPUT_FILE = @"MyFile.xfdl";
string outputFile = Path.ChangeExtension(INPUT_FILE, ".xml");

/*--- Load file contents ---*/
var fileContent = File.ReadAllText(INPUT_FILE);

/*--- Strip out first line ---*/
var pos = fileContent.IndexOf('\n') + 1;
var s = fileContent.Substring(pos);

/*--- Decode Base64 to Binary ---*/
var bytes = Convert.FromBase64String(s);
var inputStream = new MemoryStream(bytes);

/*--- Ungzip ---*/
using (FileStream outputStream = File.Create(outputFile))
{
    using (GZipStream gZip = new GZipStream(inputStream, CompressionMode.Decompress))
    {
        gZip.CopyTo(outputStream);
    }
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.