Documentation ¶
Overview ¶
Package file_streamer provides a file streaming service that streams all data from a file into a buffered writer.
It uses fsNotify for detecting changes in files, reads that changes (new data) and writes them into a buffered writer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotRunning is an error returned when action can't be finished because Streamer service is not running yet // Streamer.Start() was not called ErrNotRunning = errors.New("streamer is not running") // ErrRunning is an error returned when action can't be finished because Streamer service is in running state ErrRunning = errors.New("streamer is running") // ErrListenerClosed is an error returned when Listener can't be used for streaming because it is already closed. ErrListenerClosed = errors.New("listener is closed") )
Functions ¶
func StreamRawData ¶
func StreamRawData(filePath string, initialOffset int64, streamer *Streamer, w http.ResponseWriter, timeout time.Duration) error
StreamRawData hijacks HTTP connection and sends raw file data into a connection buffer.
It does not send any additional information like HTTP headers and does not check connection in any way before sending data. Being used 'as is' it breaks HTTP protocol (sends no headers to a clien) and should not be considered as a correct way to send file data as a part of regular HTTP interaction.
To stream file data inside a valid HTTP response without breaking a connection structure, send headers and any other metadata you want to a client before calling StreamRawData().
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is used for making Streamer to stream data from specific sile to specific buffered writer. Simply, it binds some *os.File to some *bufio.Writer Use NewListener for getting initialized Listener structure ready for usage in Streamer.
func NewListener ¶
NewListener creates initialized Listener ready to be provided to Streamer.StreamTo() function
type Streamer ¶
type Streamer struct {
// contains filtered or unexported fields
}
Streamer is a main package instance that provides streaming service to all Listeners
func New ¶
New creates new instance of file streamer. Usually, you don't need more than one instance of Streamer.
func (*Streamer) IsRunning ¶
IsRunning is a thread-safe way to check Streamer is in 'Running' state.
'Running' state means Streamer reads fsNotify events on files, reads data from files and streams it to buffered writers.
func (*Streamer) Start ¶
Start streamer.
Makes Streamer's .StreamTo() available for Listeners. After return from this function Streamer is able to stream files into buffered writers.
Thread safe.
func (*Streamer) Stop ¶
Stop streamer.
Prevents new streams creation, finishes all existing subscriptions and stops all internal goroutines.
Thread safe.
func (*Streamer) StreamTo ¶
StreamTo makes streamer to start data streaming for Listener. StreamTo will block until <listener> is closed (listener.Close() is called) or file is not modified more than <timeout> time.
Zero value ('0') as <timeout> disables timeout at all, making Streamer to stream data until Listener is closed (by .Close() call)
returns ErrNotRunning when Streamer is not ready for streaming data (was not Start()'ed, or was Stop()'ed)
returns ErrListenerClosed when listener is not ready for accepting data.
Notes ¶
Bugs ¶
on kqueue systems (like MacOS X, for example) file_streamer can't stream named pipes. 'kqueue' can't notify about FIFO file events, so fsNotify just does not provide any signals on data writes to a FIFO file.