Wormhole

While developing tools for StratOS, I wrote a nifty little program that I call "Wormhole," which uses the Linux kernel's inotify functionality to respond to filesystem events. More specifically, it watches a single directory and performs specified actions on any files that are moved into or written to the directory. Once the files are processed, the results are stored in another directory. The syntax is like this:

$ wormhole action entrance_directory exit_directory
where the action is either a program name or one of the built-in commands: --zip or --unzip. The program that is used as the action, must take two input arguments: an input file and an output directory. Wormhole expects the action to remove the input file from the entrance_directory as its final step. The simplest (very silly) example is:
$ wormhole mv /directory1/  /directory2/
In this example, the action is the move command, mv. Whenever a file is added to /directory1, it will automatically be moved to /directory2.

A more realistic use case would involve a script that performs some sort of useful operations on the files that enter the entrance_directory. Here's a slightly less silly example action:

#! /bin/bash

# pdf_append.sh - A command for adding new pages to a PDF file
# usage: pdf_append.sh input_image output_directory
# where input_image is an image file that can be processed with
# ImageMagick's convert command and output_directory contains
# exactly one PDF document.
# Note that this is a very fragile script for demonstration
# purposes only.

input_image=$1
output_dir=$2

# convert image to PDF 
# (this assumes the input isn't already a PDF)

input_pdf="$input_image.pdf"
convert $input_image $input_pdf

# get the name of the PDF being appended to.
# assumes there is exactly one PDF file in output_dir 

output_pdf="$(ls $output_dir/*.pdf)"

temp_pdf="${output_pdf/.pdf/-temp.pdf}"

# append the input_pdf to the end of the output_pdf

mv $output_pdf $temp_pdf

pdfunite $temp_pdf $input_pdf $output_pdf
# these tools would also work: 
# pdftk $temp_pdf $input_pdf cat output $output_pdf 
# pdfjoin $temp_pdf $input_pdf $output_pdf

# delete intermediate files:

rm $input_image $input_pdf $temp_pdf

Suppose I create directories in my current working direcotry, called in/ and out/. Inside of the out/ directory, I place a PDF document. I then execute wormhole, like this:
$ wormhole ./pdf_append.sh in out 
Now, if I save or move images into the in/ directory, they will automatically be appended to the PDF document in out/ as new pages.

Wormhole was initially developed to provide a means of automatically compressing and decompressing files before they are sent over a non-compressed network stream (specifically, NFS), so it has two built-in actions, --zip and --unzip. These actions currently use zlib to perform the compression, but they will eventually use the LZO compression library, due to its compression speed. The input and output directories are in RAM-backed, tmpfs file systems in order to minimize latency. The sender places files into one "mouth" of the wormhole and files are compressed and sent to the destination computer. The receiver watches the other mouth of the worm hole and decompresses files as they arrive.

The current version of Wormhole isn't written to be a proper daemon, but it can be cheaply "daemonized" using nohup and output redirection. For example:

$ nohup wormhole --zip /path/to/in /path/to/out 1> /dev/null 2>/dev/null &
The source for the version of Wormhole described above can be found here.

35 Responses to “Wormhole”

  1. Margaret S Says:

    Thank you for sharing the version of Wormhole. I'll try to figure out how it works.

  2. waqas junaid Says:

    linux kernel networking pdf is a book learned for Hierarchy of networking layers, Networking Data Structures, NAPI, Routing Subsystem, Receiving a packet, Sending a Packet, and Multipath routing. computersciencepdf.com/linux-kernel-networ...

  3. Check Cashing Says:

    Getting the money for checks, for instance, is a great deal simpler these days than it was previously. In the not so distant past, getting the money for checks implied anguishing long queues in banks.

  4. webstagram Says:

    Thank you for sharing the article. Glad to find this post.
    instagram search

  5. JordanSpave Says:

    nevermind

  6. billywelsh Says:

    I’m an academic writer who loves to bring smiles to people's face.

    Writing is what I do for a living and I am so passionate about this. I have worked with several organizations whose mission is to help people solve problems.
    I love traveling and have visited several countries in the past few years.
    I’m happy to have written several books that have contributed positively to the lives of many. My works are available in several parts of the world. And I’m currently working with companies that help people save energy. Being a part of this team has open more opportunities for me to excel as a writer. I have worked with different people and met many clients as a professional.
    I can handle any kind of writing project and provide nothing but the best. People come to me all the time to ask if I can solve their writing problems and I accept. I find pleasure in helping them to solve their problems as a writer.

    Professional Writer – Billy Welsh - Techwritersclub Team

  7. eesawalt Says:

    Hi Everybody
    Thanks for checking out my writing website . My name is Noah.
    I have worked a long time in this niche. My passion for writing started at a young age. I wrote short stories as a child and eventually went on to work with my school newspaper.
    This early tryst into news reporting eventually led me to academic writing. There is plenty of work for professional writers. I specialize in essays, but have the skills to do all types of academic writing.
    Contact me for more information about rates and a price quote. I’m looking forward to helping you.

    Academic Writer – Noah – Myessaypartner Confederation

  8. cynthianav Says:

    Thanks for stopping by my page! I’m Cynthia.
    Even though I jokingly credit my aunt for my writing talent, I know that it is a ability I have fostered from childhood. Though my aunt is a writer, I also started out young.
    I’ve always had a way with words, according to my favorite teacher . I was always so excited in history when we had to do a research writing assignment.
    Now, I help current learners achieve the grades that have always come easily to me. It is my way of giving back to students because I understand the obstacles they must overcome to graduate.

    Cynthia Nava – Professional Writer – Weuniteconference Corps

  9. Onetogel Says:

    Onetogel

  10. 123Togel Says:

    123Togel

  11. Riatoto Says:

    Riatoto

  12. Champion4d Says:

    Champion4d

  13. Visatogel Says:

    Visatogel

  14. Dewanalo Says:

    Dewanalo

  15. Mentari4d Says:

    Mentari4d

  16. QQpokerceme Says:

    QQpokerceme

  17. Zienpoker Says:

    Zienpoker

  18. Inulpoker Says:

    Inulpoker

  19. Hm88poker Says:

    Hm88poker

  20. Sarangdomino Says:

    Sarangdomino

  21. Depodewa Says:

    Depodewa

  22. Pokerbo Says:

    Pokerbo

  23. Genkpoker Says:

    Genkpoker

  24. Pokerhokibet88 Says:

    Pokerhokibet88

  25. Divatogel Says:

    Divatogel

  26. Pedia4d Says:

    Pedia4d

  27. Woke4d Says:

    Woke4d

  28. Tiara4d Says:

    Tiara4d

  29. Result Hk Tercepat Says:

    Result Hk Tercepat

  30. Live Hk Toto Says:

    Live Hk Toto

  31. Live Draw Sydney Says:

    Live Draw Sydney

  32. Live Sgp Tercepat Says:

    Live Sgp Tercepat

  33. Live Hk 6d Says:

    Live Hk 6d

  34. Prediksi Togel Says:

    Prediksi Togel Hari Ini

  35. Nonton Live Bola Says:

    Nonton Live Bola

Leave a Reply