Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Last active October 29, 2016 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/f5e843602abe4f6331e653670bd87e38 to your computer and use it in GitHub Desktop.
Save thinkerbot/f5e843602abe4f6331e653670bd87e38 to your computer and use it in GitHub Desktop.
Stream compress, encrypt, decrypt, uncompress
#!/bin/bash
# http://unix.stackexchange.com/questions/79525/openssl-buffering-problem
# http://stackoverflow.com/questions/570984/how-can-i-gzip-standard-in-to-a-file-and-also-print-standard-in-to-standard-out
time (
ruby -e "STDOUT.sync=true; 100000.times {|i| puts(i.to_s + ' knowledge is power') }" |
gzip --stdout |
openssl enc -aes-128-cfb -pass pass:test -bufsize 256 |
openssl enc -base64 -bufsize 256 |
openssl enc -base64 -d -bufsize 256 |
openssl enc -d -aes-128-cfb -pass pass:test -bufsize 256 |
gunzip --stdout > /dev/null
)
#!/bin/bash
time (
ruby -e "
STDOUT.sync=true
STDERR.sync=true
puts(i.to_s + ' knowledge is power')
#sleep 5
#sleep 1
#sleep 0.1
end
" |
ruby -e '
STDOUT.sync=true
STDERR.sync=true
buffer = ""
max_time = 3.0
last_time = Time.now
loop do
STDERR.puts "loop"
time_elapsed = Time.now - last_time
time_remaining = max_time - time_elapsed
if time_remaining < 0
if buffer.length > 0
STDERR.puts "pad"
buffer = buffer.ljust(256, ".")
else
STDERR.puts "reset"
last_time = Time.now
end
else
if IO.select([STDIN], nil, nil, time_remaining)
buffer += STDIN.read_nonblock(256 - buffer.length)
end
end
if buffer.length == 256
print buffer
buffer = ""
last_time = Time.now
end
end
' |
openssl enc -aes-128-cfb -pass pass:test -bufsize 256 |
openssl enc -d -aes-128-cfb -pass pass:test -bufsize 1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment