Created
October 31, 2014 20:13
-
-
Save zwetan/6bbeea67e952edcba7cd to your computer and use it in GitHub Desktop.
CGI example 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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