streaming - Ruby CGI Stream Audio -


What I want to do is to use a CGI script (written in Ruby) to use the file system (audio, special ) And stream it in the browser.

In this way I am doing so by now,

  'config' ENV ['REQUEST_URI'] = ~ / \? (. *) $ / F = $ config [: mdir] + '/' + $ 1.Ur_decodeF = file. OpenF, 'RB' print "content-type: audio / mpeg \ r \ n" #TODO: MME type print looks "\ r \ n" #Outputs file while blk = f.read (4096) $ stdout It's not right, there are security holes (highlighting the entire file system ..), but it does not work right. Blk $ stdout.flush end f.close  

This is reading the correct file, and as far as I can tell, it should output to 4k blocks as if it should be Using Safari, if I go to URL, it will show a question mark on the audio player. If I use wget to download it, then it appears to work and is about the right size but is corrupt. It starts playing fine, then the cranks, and then closes.

How should I go about doing this? Do I need a base-64 encode, if I can do the whole file without loading it in a single memory?

BTW, this is going to be used only on the local area network, and I want that easy setup, so I'm not interested in a dedicated streaming server.

You simply enter IO # instead of IO # print but it has some disadvantages.

Do not handle files in Ruby

Ruby is not good at doing stupid work Very fast with this code, you probably will not be able to fill your bandwidth.

No CGI

Whatever you want to do, it exposes a part of the file system through http, here are some options how to do this

  • Set your document root in the folder you want to show.
  • Create a symlink to the folder that you want to show.
  • Write some rules to map some URLs into a folder in your webserver config

Use any of these and what the http server wants to do for you. .

X-Sendfile

Some HTU home servers respect a special header named X-Sendfile. If you do

  print "X-Sendfile: # {file}"  

then the server will use the specified file as the body. In light it only works via fastcgi, so you will need a fastcgi wrapper: I do not know about Apache and others.

Use a C extension

The C extension is good at accelerating stupid functions. I have written a single extension which does nothing, but is reading from an IO And it's writing in another IO. With this extension you can fill a GIGABIT LAN via Ruby: git: //johannes.krude.de/io2io

Use it like this:

  IO2IO.do (file, STDOUT)  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -