I am puzzled by how they actually encoded the PNG as a String, I tried a couple of alternatives but I could not get binary data out of it so that it parsed successfully as PNG. If I would have to encode binary data in JSON I would use Base64 encoding (but alternatives exist).
On 24 Apr 2017, at 20:36, Juraj Kubelka <juraj.kubelka@icloud.com> wrote:
Hi,
I was playing with GitHub Gist API and I have queried the following Gist: https://gist.github.com/mbostock/5503544 I was interested how the PNG image is returned: https://gist.github.com/mbostock/5503544#file-thumbnail-png
I can obtain the whole Gist executing:
STONJSON fromString: (ZnClient new url: 'https://api.github.com/gists/5503544'; accept: 'application/vnd.github.v3+json'; get).
I can get PNG contents executing:
pngData := (ZnEasy get: ((((STONJSON fromString: (ZnClient new url: 'https://api.github.com/gists/5503544'; accept: 'application/vnd.github.v3+json'; get)) at: 'files') at: 'thumbnail.png') at: 'raw_url')) contents. PNGReadWriter formFromStream: rawPng readStream.
But the PNG image is part of the Gist query and can be retrieved by:
pngContent := ((((STONJSON fromString: (ZnClient new url: 'https://api.github.com/gists/5503544'; accept: 'application/vnd.github.v3+json'; get)) at: 'files') at: 'thumbnail.png') at: 'content').
"As pngContent is a WideString, I cannot use:" PNGReadWriter formFromStream: pngContent readStream.
How can I read the PNG image from the pngContent? Any idea? And the reverse question: How can I send the PNG bytes using JSON format?
Thanks! Juraj