func (r *sessionRecorder) Write(data []byte) (int, error) {
	const (
		minChunkLen   = 4
		maxDelay      = time.Millisecond * 20
		requiredDelay = time.Millisecond * 5
	)
	// terminal recording is a tricky business. the TTY subsystem expects a certain
	// delay when it writes to a virtual console. In our case recording takes no time
	// so we have to emulate TTY delay here:
	var start time.Time

	// the delay depends on the chunk size, but shouldn't be higher than a certain
	// ceiling (maxDelay)
	dataLen := len(data)
	if dataLen > minChunkLen {
		start = time.Now()
		defer func() {
			postingDuration := time.Now().Sub(start)
			if postingDuration < requiredDelay {
				delay := time.Millisecond * time.Duration(dataLen)
				if delay > maxDelay {
					delay = maxDelay
				}
				time.Sleep(delay)
			}
		}()
	}
	// post the chunk of bytes to the audit log:
	if err := r.alog.PostSessionChunk(r.sid, bytes.NewReader(data)); err != nil {
		log.Error(err)
	}
	return dataLen, nil
}
// Write takes a chunk and writes it into the audit log
Write takes a chunk and writes it into the audit log
// Write takes a chunk and writes it into the audit log
func (r *sessionRecorder) Write(data []byte) (int, error) {
	const (
		minChunkLen   = 4
		maxDelay      = time.Millisecond * 20
		requiredDelay = time.Millisecond * 5
	)
	var start time.Time
	dataLen := len(data)
	if dataLen > minChunkLen {
		start = time.Now()
		defer func() {
			postingDuration := time.Now().Sub(start)
			if postingDuration < requiredDelay {
				delay := time.Millisecond * time.Duration(dataLen)
				if delay > maxDelay {
					delay = maxDelay
				}
				time.Sleep(delay)
			}
		}()
	}
	if err := r.alog.PostSessionChunk(r.sid, bytes.NewReader(data)); err != nil {
		log.Error(err)
	}
	return dataLen, nil
}
func ( r * sessionRecorder ) Write ( data [ ] byte ) ( int , error ) { const ( minChunkLen = 4 maxDelay = time . Millisecond * 20 requiredDelay = time . Millisecond * 5 ) var start time . Time dataLen := len ( data ) if dataLen > minChunkLen { start = time . Now ( ) defer func ( ) { postingDuration := time . Now ( ) . Sub ( start ) if postingDuration < requiredDelay { delay := time . Millisecond * time . Duration ( dataLen ) if delay > maxDelay { delay = maxDelay } time . Sleep ( delay ) } } ( ) } if err := r . alog . PostSessionChunk ( r . sid , bytes . NewReader ( data ) ) ; err != nil { log . Error ( err ) } return dataLen , nil }
Write takes a chunk and writes it into the audit log
Write takes a chunk and writes it into the audit log
// terminal recording is a tricky business. the TTY subsystem expects a certain // delay when it writes to a virtual console. In our case recording takes no time // so we have to emulate TTY delay here: // the delay depends on the chunk size, but shouldn't be higher than a certain // ceiling (maxDelay) // post the chunk of bytes to the audit log: