Re: Base64 partial decoding



Gelembjuk wrote:
Hello.
I have data encoded with base64. I need to decode it but i must to do
it part by part.
I read bytes from stream. I must read some part (8000 bytes or any
other count that is not too big, less then 10000) then i need to
decode this part of data and write to another stream.

I found that if i just read part of data and decode it with
base64_decode then final decoded data are not correct.
If there a way to decode base64 encoded data part by part?

Interesting problem you have, I can understand why you want to decode only sections of a base64 encoded stream and not the entire lot .

base64 encoded string "hello world" gets turned into aGVsbG8gd29ybGQ=

now its been a long time since ive done bitwise encoding ( back in asm/pascal graphic programming days for dos ) so i had to look up how base64 encoding works
found a nice article on how it works
http://email.about.com/cs/standards/a/base64_encoding.htm
its mostly about email but its a good start


if you miss grab the wrong parts you can get erroneous results.
Now assuming if its practical and you know the exact structure of the stream you could use functions like chunk_split ,unpack or even preg functions to get the correct data.

personally i would do a base64_decode and work on the resulted string thereafter.

Without knowing exactly what your source or your code is thats the best I can offer


regards trookat
.



Relevant Pages

  • Re: Decoding Base64
    ... i am trying to decode a block of base64 into text, ... Richard Heathfield ... I've no idea what Richard has said else where, but his attitude to your posting here is hardly surprising. ... What do you think your local computer store would tell you if you took a printout of that code in and asked how to decode it? ...
    (comp.lang.c)
  • Re: Base64
    ... | pass a base64 encoded string into and get back a decoded String. ... ** encodeencodes an arbitrary data block into MIME Base64 format string ... int encode(unsigned s_len, char *src, unsigned d_len, char *dst) ... ** DECODE BASE64 into RAW ...
    (comp.lang.c)
  • Re: Integer data type -> binary coded decimal
    ... While it doesn't answer your specific question, here is a routine to ... decode base64 data. ... It will decode the data into separate 3-byte pieces ... the end of the base64 string. ...
    (microsoft.public.sqlserver.programming)
  • Re: Decoding Base64
    ... Richard Heathfield wrote: ... i am trying to decode a block of base64 into text, ... if i knew how it was encoded, i'd know how to decode it. ... i know nothing about this sort of computer speak. ...
    (comp.lang.c)
  • Re: Reading sections of MP3/WMA files
    ... is the boundary of an audio frame. ... type will tell you the block align of the stream and a block ... You may want to take a look at my sample MP3 parser to know ... a decode to memory takes. ...
    (microsoft.public.windowsmedia.sdk)