Skip to main content
hints added
Source Link
Kamil Maciorowski
  • 24.5k
  • 2
  • 69
  • 129

Even if I separate the files with \004 before sending them to stdout ...

Good thing you can modify the sending procedure. My solution is as follows:

for f in *.jpg; do echo S; base64 "$f"; echo ""; done | # the above is just an example sending process while read dummy; do sed -u '/^$/q' | base64 -d | identify - done 

Clarification:

  • Single "file block" starts with an expendable line ("S" in this case) that carries no data. If read cannot find a line, the whole command ends.
  • sed passes data to decoder until there's an empty line (note: additional empty line doesn't change the output of base64 -d).
  • It's crucial to use unbuffered sed (-u flag); otherwise one sed could read too much and eventually discard what it thinks is excessive data; then the next sed (consequently the next identify) wouldn't get all the data it should.

The extra line can carry metadata. CompareHints:

for f in *.jpg; do printf "%s\n" "$f"; base64 "$f"; echo ""; done | # the above is just an example sending process while read fname; do printf "%s " "$fname" sed -u '/^$/q' | base64 -d | identify - | cut -f 2- -d " " done 
  • The extra line can carry metadata instead of "S", like a filename or so (but beware of newlines in names etc.).
  • Because base64 produces bigger output than its input, you may want to use gzip on the both sides, especially if your stream travels via the Internet.

Even if I separate the files with \004 before sending them to stdout ...

Good thing you can modify the sending procedure. My solution is as follows:

for f in *.jpg; do echo S; base64 "$f"; echo ""; done | # the above is just an example sending process while read dummy; do sed -u '/^$/q' | base64 -d | identify - done 

Clarification:

  • Single "file block" starts with an expendable line ("S" in this case) that carries no data. If read cannot find a line, the whole command ends.
  • sed passes data to decoder until there's an empty line (note: additional empty line doesn't change the output of base64 -d).
  • It's crucial to use unbuffered sed (-u flag); otherwise one sed could read too much and eventually discard what it thinks is excessive data; then the next sed (consequently the next identify) wouldn't get all the data it should.

The extra line can carry metadata. Compare:

for f in *.jpg; do printf "%s\n" "$f"; base64 "$f"; echo ""; done | # the above is just an example sending process while read fname; do printf "%s " "$fname" sed -u '/^$/q' | base64 -d | identify - | cut -f 2- -d " " done 

Even if I separate the files with \004 before sending them to stdout ...

Good thing you can modify the sending procedure. My solution is as follows:

for f in *.jpg; do echo S; base64 "$f"; echo ""; done | # the above is just an example sending process while read dummy; do sed -u '/^$/q' | base64 -d | identify - done 

Clarification:

  • Single "file block" starts with an expendable line ("S" in this case) that carries no data. If read cannot find a line, the whole command ends.
  • sed passes data to decoder until there's an empty line (note: additional empty line doesn't change the output of base64 -d).
  • It's crucial to use unbuffered sed (-u flag); otherwise one sed could read too much and eventually discard what it thinks is excessive data; then the next sed (consequently the next identify) wouldn't get all the data it should.

Hints:

  • The extra line can carry metadata instead of "S", like a filename or so (but beware of newlines in names etc.).
  • Because base64 produces bigger output than its input, you may want to use gzip on the both sides, especially if your stream travels via the Internet.
Source Link
Kamil Maciorowski
  • 24.5k
  • 2
  • 69
  • 129

Even if I separate the files with \004 before sending them to stdout ...

Good thing you can modify the sending procedure. My solution is as follows:

for f in *.jpg; do echo S; base64 "$f"; echo ""; done | # the above is just an example sending process while read dummy; do sed -u '/^$/q' | base64 -d | identify - done 

Clarification:

  • Single "file block" starts with an expendable line ("S" in this case) that carries no data. If read cannot find a line, the whole command ends.
  • sed passes data to decoder until there's an empty line (note: additional empty line doesn't change the output of base64 -d).
  • It's crucial to use unbuffered sed (-u flag); otherwise one sed could read too much and eventually discard what it thinks is excessive data; then the next sed (consequently the next identify) wouldn't get all the data it should.

The extra line can carry metadata. Compare:

for f in *.jpg; do printf "%s\n" "$f"; base64 "$f"; echo ""; done | # the above is just an example sending process while read fname; do printf "%s " "$fname" sed -u '/^$/q' | base64 -d | identify - | cut -f 2- -d " " done