Skip to content

Instantly share code, notes, and snippets.

@thinkerbot thinkerbot/example.sh
Last active Oct 29, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.