Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Help reg, Xceed Binary Encoding Library

Sort Posts: Previous Next
  •  12-05-2007, 7:05 AM Post no. 6273

    Help reg, Xceed Binary Encoding Library

    Hey,

    I’m using Xceed Binary Encoding Library 1.1, to encode a Macintosh file to HQX format before sharing it through Email. I have a MAC file which has got the DataFork and resource fork as different streams in the same file(AppleShare File). While setting the encoding properties I’m having issues in setting the HeaderDataForkLength and HeaderResourceForkLength properties.

    As per your documentation, HeaderDataForkLength + HeaderResourceForkLength = Total No of Bytes for Encoding. But since the file stores the resource fork in a different stream, the total file size of the input file is only the datafork length ( Size of the data fork alone). So if I set the HeaderDataForkLength property to the data fork size, and the HeaderResourceForkLength to the resource fork size (I get this by reading size of “<FileName>+ :AFP_Resource “stream), I get an exception stating that the total size of HeaderDataForkLength and HeaderResourceForkLength exceeds the total file size. Is there any work around for overriding this condition HeaderDataForkLength + HeaderResourceForkLength = Total No of Bytes for Encoding?



    I would expect a clear explanation of the solution you can offer, otherwise the license I have would be of little help for me.



    I believe the following code sample would be useful for you to have a better understanding of what I am trying to do.



    //C# …………………………………………………………………………………………………………………………………………………………………..



    string sourceFileName = FileToConvert.FullName;

    string destinationFileName = sourceFileName + ".hqx";

    int dataForkLength,resourceForkLength,resourceInfoLength;



    EncodeDecodeOptions encodeDecodeOptions = new EncodeDecodeOptions();



    XceedBinHexEncodingFormatClass encodingFormat = new XceedBinHexEncodingFormatClass();





    // When encoding, the output file should have BinHex formating.

    encodingFormat.IncludeHeaderFooter = true;



    // Set the End of line type and the Maximum line length.

    encodingFormat.EndOfLineType = encodeDecodeOptions.EndOfLineType;

    encodingFormat.MaxLineLength = encodeDecodeOptions.MaxLineLength;



    // For the BinHex format, we must specify the data fork length and the

    // resource fork length.]

    int fileSize = ( int )(new FileInfo( sourceFileName )).Length;



    //Finding the length of Data fork

    IntPtr hflp = CreateFile( sourceFileName, 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero );

    if( (int)hflp == INVALID_HANDLE_VALUE )

    {

    dataForkLength = ( int )(new FileInfo( sourceFileName )).Length;

    }

    else

    {

    dataForkLength = (int)(new FileStream(hflp,FileAccess.Read)).Length;

    }



    //Finding the Resource Fork Length

    hflp = CreateFile( sourceFileName+":AFP_Resource", 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero );

    if( (int)hflp == INVALID_HANDLE_VALUE )

    {

    resourceForkLength = 0;

    }

    else

    {

    resourceForkLength = (int)(new FileStream(hflp,FileAccess.Read)).Length;

    }



    //Finding the Resource Info Length and adding it to resource fork

    hflp = CreateFile( sourceFileName+":Afp_AfpInfo", 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero );

    if( (int)hflp == INVALID_HANDLE_VALUE )

    {

    resourceInfoLength = 0;

    }

    else

    {

    resourceInfoLength= (int)(new FileStream(hflp,FileAccess.Read)).Length;

    }

    AbstractFile processedFile= null;



    //Processing the Data Fork

    if(dataForkLength>0)

    {

    encodingFormat.HeaderDataForkLength = dataForkLength;

    encodingFormat.HeaderResourceForkLength = 0;

    //Set the encoding format.

    xEncoder.EncodingFormat = encodingFormat;

    processedFile = ProcessFile(sourceFileName,destinationFileName,xEncoder);

    }



    return processedFile;



    //………………………………………………………………………………………………………………………………………………………………………………..









    Even though there are some advanced MacMIME techniques available for sharing MAC files over the network, since we are using this HQX encoding in one of our products for a long time, we would like to stick to the same format


    Regards,

    Bala Rajesh.B,
  •  12-07-2007, 4:22 PM Post no. 6274 in reply to 6273

    Re: Help reg, Xceed Binary Encoding Library

    This issue was resolved through e-mail support.

    In our BinaryEncoding library, there is 2 main ways of accomplishing this.

    One way is the one you are trying to use in the code you provided, using the ProcessFile method.

    The only other way to be able to process multiple source, is to read the data yourself by opening the file, read the amount of data you want, and call the .Encode() method. As stated in the documentation, it will return a Byte array of encoded data, and receive a Byte array and an end of data indicator.

    So, in this particular situation. After initializing the encodingFormat.Header* info, you will first open the destination file and the DataFork file. Loop in the DataFork by reading segment of about 128k ( or more, like you wish or more optimal ) in a byte array, pass the read buffer to the .Encode method with false for the second parameter has an indication of the data is not finished yet. Then, you use the returned buffer to write it in your destination file. After you are done with the DataFork file, do the same with the ResourceFork file, but don't forget to do the last call to .Encode with true to the second parameter.

    Note : Since you are using am ActiveX product in .NET, there can be a cost from calling multiple time "unmanaged" code from managed code. I think the higher the read buffer will be, the better the performance will be. But it will consume more memory. So it is a manner of balancing memory vs performance.
    Charles Bérubé-Rémillard
    Technical Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.