Author Topic: Read and Write PIA Files  (Read 511 times)

0 Members and 1 Guest are viewing this topic.

kaefer

  • Swamp Rat
  • Posts: 538
Read and Write PIA Files
« on: April 19, 2012, 07:00:47 am »
The same procedure as every couple of years : After IT migrated to new servers, all PC3-saved printer paths are invalid. Either that or there are other reasons to read and write the special format in which AutoCAD's plotter support files are saved.

First, here's a short description of the PIA (whatever that may stand for) file format.
Secondly, since Zlib streams aren't part of the runtime, I needed to download the dotnetzip library, in order to reference zlib-v1.9\Ionic.Zlib.dll.


Code - F#: [Select]
  1. type System.IO.Stream with
  2.    member me.WriteString (s : string) =
  3.        let buf = s.ToCharArray() |> Array.map byte
  4.        me.Write(buf, 0, buf.Length)
  5.  
  6. module Zlib =
  7.    open System.IO
  8.    open Ionic.Zlib
  9.  
  10.    let read fileName =
  11.        use fs = File.Open(fileName, FileMode.Open, FileAccess.Read)
  12.        fs.Seek(60L, SeekOrigin.Begin) |> ignore
  13.        use zs = new ZlibStream(fs, CompressionMode.Decompress)
  14.        use sr = new StreamReader(zs)
  15.        let s = sr.ReadToEnd()
  16.        sr.Close()
  17.        s
  18.  
  19.    let write fileName s =
  20.        use fs = File.Open(fileName, FileMode.Create, FileAccess.ReadWrite)
  21.        use zs =
  22.            new ZlibStream(
  23.                fs, CompressionMode.Compress,
  24.                CompressionLevel.BestCompression, false )
  25.        fs.WriteString(
  26.            "PIAFILEVERSION_2.0,CTBVER1,compress\r\npmzlibcodec" +
  27.            "\255\255\255\255\255\255\255\000\255\255\255\000" )
  28.        zs.WriteString s
  29.        zs.Close()

The read function will give you a string which is, to quote, "more or less 'human readable'".

whoknows

  • Newt
  • Posts: 68
Re: Read and Write PIA Files
« Reply #1 on: April 21, 2012, 04:33:18 pm »
...
First, here's a short description of the PIA
...

About "here's" (http://www.noliturbare.com/more/faq#Q1):
is a good starting point, but contains several errors/lack of information
The header size is 60 No 59
bytes 49->52 = ZlibCodec.Adler32
bytes 53->56 = compressed stream size
bytes 57->60 = decompressed stream size

Look @ this:
http://www.theswamp.org/index.php?topic=37625.0

« Last Edit: April 21, 2012, 04:50:36 pm by whoknows »
That's all folks