Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drip - pipe data streams as they drip

Drip is both a CLI application (drip) and C library (libdrip) to pipe data streams from a file or Unix FD (e.g. socket, stdin), with a freely set time interval and ways to split (bandwidth, lines, any characters, any string, etc), to another file or Unix FD (e.g. socket, stdout).

Drip is also a test ground for C++-like implementation header + instantiation abstraction ideas in C, see src/impl.h and src/libdrip.c.

Structure

drip/
├── CMakeLists.txt -> Instruction to build with CMake
├── include/
│   └── drip.h    -> Public header to include in other projects
├── LICENSE        -> License file
├── README.md      -> This documentation
└── src/
    ├── common.h   -> Common part for `libdrip` implementation and instantiation
    ├── drip.c     -> Source for CLI application `drip`
    ├── impl.h     -> Implementation for `libdrip`
    └── libdrip.c  -> Instantiation for `libdrip`

Build

To build in tree:

cmake -B build
cmake --build build

In the build folders pick what you need from the following files:

build/
├── ...
├── drip                             -> Dynamically linked `drip` CLI, needs also `libdrip.so`
├── drip-static                      -> Statically linked `drip` CLI, can run standalone
├── libdrip.a                        -> Static library `libdrip`
├── libdrip.so -> libdrip.so.0       -> Symlink for dynamic library
├── libdrip.so.0 -> libdrip.so.0.0.1 -> Symlink for dynamic library
└── libdrip.so.0.0.1                 -> Dynamic library `libdrip`

libdrip

The main functionality of drip (i.e. the part that controls the data streams) is contained in libdrip; when building drip both libdrip.so and libdrip.a would be built, useful each for dynamic linking and static linking

When using libdrip, include drip.h in your project, and link to either libdrip-shared or libdrip-static as you like.

The below example moves data from stdin to stdout, 2 words (seperated by a single space) a time, with a 0.1 second interval:

#include <drip.h>
#include <stdio.h>
#include <unistd.h>

int main() {
    DripLimit const limit = {
        .interval = {
            .tv_sec = 0,
            .tv_nsec = 100000000,
        },
        .count = 2,
        .sep = ' ',
        .by = DripBySplitChar,
    };
    int const sts = drip_fd_to_fd(limit, STDIN_FILENO, STDOUT_FILENO);
    if (sts) {
        fprintf(stderr,
            "Failed to drip from stdin to stdout, error: %s\n",
            drip_sts_explain(sts)
        );
        return 1;
    }
    return 0;
}

Save the above example as example.c, then compile and test with:

gcc -o example -Iinclude example.c build/libdrip.a
./example < /usr/bin/makepkg

Also, the source file to drip CLI, src/drip.c, can be considered as a demo application; the above example can be done with drip CLI via:

drip -t .1 -n 2 -i /usr/bin/makepkg -c ' '

Drip CLI

drip (--version/-v) (--help/-h) (--input/-i [path]) (--output/-o [path]) (--interval/-t [time]) (LIMITER)

All of the non-limiter arguments are optional:

  • --version/-v prints the version and early quit
  • --help/-h prints the help message and early quit
  • --input/-i [path] defines the input file path, - for stdin (default)
  • --output/-o [path] defines the output file path, - for stdout (default)
  • --interval/-t [time] defines the interval in second, can be fractional and the integral part can be omitted for 0, e.g. 1.625 for 1 second and 625 milliseconds, .125 for 125 milliseconds; default 1 for 1 second
  • --count/-n [number] defines how many byte/line/chunks (depending on limiter, see below) to output in one interval; default 1

Exactly one limiter shall be set (the N below can be set from --count/-n [number] argument mentioned above):

  • --by-bytes/-b limits rate to N bytes per interval
  • --by-unixlines/-u limits rate to N Unix lines (seperated by \n) per interval
  • --by-lines/-l limits rate to N Unix/Mac/Windows lines (seperated by either \n, \r, or \r\n) per interval
  • --by-splitchar/-c [char] limits rate to N chunk (seperated by set character) per internal, the character can be either:
    • empty ('') for NULL-seperated, or
    • a single literal characer, e.g. ,, or
    • 0b/0x-prefixed sequence or simply a decimal (or oct) number for the encoded character, e.g. 0xd or 14 for \r, 0b1010 or 012 for \n
  • --by-splitstr/-s [str] limits rate to N chunks (seperated by set C-string; no internal escaping would be done) per interval, e.g. Frame skipped
  • --by-splitfile/-f [file] same as split-str, but the str comes from respective file (whole content) so no escape needs to be worried, and NULL can be part of the split-string, e.g. /tmp/split.txt

License

Drip is licensed under GPL3

  • Copyright (C) 2026-2026 Guoxdin "7Ji" Pu (pugokushin@gmail.com)
  • This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version * of the License, or (at your option) any later version.
  • This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  • You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

About

pipe data streams as they drip

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages