File encoding strategy question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Robert

    #1

    File encoding strategy question

    Hi everyone,

    I am in the process of creating a file transmit/receiver program using
    MQSeries.

    The way it works is through creation of an XML message.

    Elements within the XML message contain things such as file name, size,
    and the file contents.

    The file contents are encoded, currently using Base64, for support of
    both binary and text data.

    This works great but there is a small rub to the problem.

    I would like to be able to view the contents of the file if it is text
    while still maintaining the ability to transmit binary data.

    Does anyone know of an encoding format that would make this possible?

    The viewing of the file contents does not need to be perfect, merely
    enough that a particular in-transit file could be identified.

    Thoughts on this would be greatly appreciated.

    Thanks,
    Andy
  • Dennis Benzinger

    #2
    Re: File encoding strategy question

    Andrew Robert schrieb:[color=blue]
    > Hi everyone,
    >
    > I am in the process of creating a file transmit/receiver program using
    > MQSeries.
    >
    > The way it works is through creation of an XML message.
    >
    > Elements within the XML message contain things such as file name, size,
    > and the file contents.
    >
    > The file contents are encoded, currently using Base64, for support of
    > both binary and text data.
    >
    > This works great but there is a small rub to the problem.
    >
    > I would like to be able to view the contents of the file if it is text
    > while still maintaining the ability to transmit binary data.
    >
    > Does anyone know of an encoding format that would make this possible?
    > [...][/color]

    Yes. You could use the Quoted-Printable encoding. See RFC 2045
    Multipurpose Internet Mail Extensions (MIME) Part One: Format of
    Internet Message Bodies <ftp://ftp.rfc-editor.org/in-notes/rfc2045.txt>


    Dennis

    Comment

    • John Machin

      #3
      Re: File encoding strategy question

      Andrew > I would like to be able to view the contents of the file if it
      is text
      while still maintaining the ability to transmit binary data.

      Like Dennis said ... and once you have read the RFC and understood it
      thoroughly :-) don't start writing code; it's one of the included
      batteries -- but beware of file size expansion for binary data:
      [color=blue][color=green][color=darkred]
      >>> import quopri
      >>> a = ''.join(chr(x) for x in range(256))
      >>> b = quopri.encodest ring(a)
      >>> c = quopri.decodest ring(b)
      >>> [len(x) for x in a,b,c][/color][/color][/color]
      [256, 530, 256][color=blue][color=green][color=darkred]
      >>> a == c[/color][/color][/color]
      True[color=blue][color=green][color=darkred]
      >>> b[/color][/color][/color]
      '\x00\x01\x02\x 03\x04\x05\x06\ x07\x08=09\n\x0 b\x0c\r\x0e\x0f \x10\x11\x12\x1 3\x14
      \x15\x16\x17\x1 8\x19\x1a\x1b\x 1c\x1d\x1e\x1f
      !"#$%&\'()*+ ,-./0123456789:;<=3 D>?@
      ABCDEFGHIJKLMNO PQRS=\nTUVWXYZ[\\]^_`abcdefghijkl mnopqrstuvwxyz{ |}~=7F=80=81=82 =8
      3=84=85=86=87=8 8=\n=89=8A=8B=8 C=8D=8E=8F=90=9 1=92=93=94=95=9 6=97=98=99=9A=9 B=9C=
      9D=9E=9F=A0=A1= \n=A2=A3=A4=A5= A6=A7=A8=A9=AA= AB=AC=AD=AE=AF= B0=B1=B2=B3=B4= B5=B6
      =B7=B8=B9=BA=\n =BB=BC=BD=BE=BF =C0=C1=C2=C3=C4 =C5=C6=C7=C8=C9 =CA=CB=CC=CD=CE =CF=D
      0=D1=D2=D3=\n=D 4=D5=D6=D7=D8=D 9=DA=DB=DC=DD=D E=DF=E0=E1=E2=E 3=E4=E5=E6=E7=E 8=E9=
      EA=EB=EC=\n=ED= EE=EF=F0=F1=F2= F3=F4=F5=F6=F7= F8=F9=FA=FB=FC= FD=FE=FF'[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      HTH,
      John

      Comment

      Working...