Skip to content

Instantly share code, notes, and snippets.

@zwetan
Created October 31, 2014 20:13
Show Gist options
  • Save zwetan/6bbeea67e952edcba7cd to your computer and use it in GitHub Desktop.
Save zwetan/6bbeea67e952edcba7cd to your computer and use it in GitHub Desktop.
CGI example 3
import C.stdio.*;
import flash.utils.ByteArray;
import shell.FileSystem;
import shell.Program;
/* NOTE:
trace() add a carriage return
better use Program.write() to
control exactly the char return at end of line
*/
Program.write( "Content-type: image/png\n" );
// read the file into binary
var file:String = "redtamarin.png";
var bytes:ByteArray = FileSystem.readByteArray( file );
bytes.position = 0;
var len:uint = bytes.length;
// we tell the browser the length and avoid to have content-transfer: chunked
Program.write( "Content-length: " + len + " \n\n" );
// write our binary to standard output
fwrite( bytes, len, stdout );
fflush( stdout );
// done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment