Figure 3: Sending stream file in the IFS to a browser


D STDIN           c                   0

D STDOUT          c                   1

      .

      .

      filename = '/home/klemscot/ifs_ebook.pdf';



      pdf = open( %trimr(filename): O_RDONLY );

      if (pdf = -1);

           // handle error

      endif;



      //

      // Specify the type of file and its filename.

      // Note: change "inline" to "attachment" to let

      //       the user save it to disk.

      //



text = 'Content-Type: Application/pdf' + CRLF + 'Content-Disposition: inline; filename=' + %trimr(filename) + CRLF + CRLF; callp write(STDOUT: %addr(text)+2: %len(text));

// // Read the contents of the PDF file in binary // mode and write it to stdout //
len = read(pdf: %addr(buf): %size(buf)); dow len > 0; callp write(STDOUT: %addr(buf): len); len = read(pdf: %addr(buf): %size(buf)); enddo;
callp close(pdf);