bytie
- convinient byte stream manipulationTODO Pictues here
bytie
allows to add, delete, replace and cut bytes of an input byte
stream or from a file. Surely, one is able to do the same thing with dd
,
however I find its command line interface a bit cumbersome at times.
Clone the repository
```sh
git clone https://github.com/awidegreen/bytie.git cd bytie ``
Build and install via
cargo`. Note that you need a fairly recent rust version.
```sh
cargo install --path . ```
NOTE: NOT YET PUBLISHED
Install bytie
from crates.io.
```sh
cargo install bytie ```
Usage
Add a string at a certain position. ```sh
echo "foobar" | bytie add -v WORLD 3 fooWORLDbar ```
Replace a string at a certain position, where replacement data comes from STDIN
.
```sh
echo "foobar" > test
echo -n "FOO" | bytie test replace 0 FOObar ```
Cut/extract bytes from input. ```sh
echo "foobar" | bytie cut 1:4 ooba ```
Delete bytes from input. ```sh
echo "foobar" | bytie delete 1+3 fr ```
General
bytie
options
bytie
has several general command line options which are valid and usable for all
subcommands:
* -b|--blocksize
: By default bytie
reads from the input with a blocksize of
1024
bytes, this can be changed using this option.
* -o|--out
: Use this option if the result should be written to a file
instead of STDOUT
.
* -i|--in-place
: Write byte manipulation output to the provided input
<file>
. This only works if <file>
has been specified.
* <file>
(optional): The input file which will act as a data source for the
subcommand operation.
NOTE: Based on the specification of the <file>
parameter, bytie
will
decide where the input data originates from. Meaning, if <file>
is omitted,
STDIN
will be used as input stream for the respective subcommand action. In
such cases, subcommands like replace
and add
will not be able take input
data for the replacement/insertion from STDIN
.
For more information consult bytie
s help (-h|--help
).
bytie
provides the following subcommand to fulfill different use cases:
NOTE:: bytie
positional indicators (start, end) start from index 0
, so
the 'b'
in foobar
is at index 4
.
cut
- Extract data from inputalias: extract
Can be used to cut/extract certain bytes from an input stream by providing the start and end position (or a length, see position parameter description below).
Cut in this context means that only the specified range will remain in the
output. In contrast to delete
which will remove bytes from the input.
delete
- Remove data from inputalias: remove
Deletes a range of bytes from the provided input stream. In contrast to cut
where the specified range will be the output. As for cut
a positional
parameter need to be specified (see below).
add
- Insert data to inputalias: insert
Inserts provided data to the input data at the specified start position
(begin
). The data to be inserted/added can originate from STDIN
or the
subcommands --value
parameter (STDIN
is only possible if source data is
not provided via STDIN
).
replace
- Replace data from inputalias: substitute
Replaces provided data at the input data at the specified start position
(begin
). The data to be replaced can originate from STDIN
or the
subcommands --value
parameter (STDIN
is only possible if source data
is not provided via STDIN
).
bytie
will always write the complete replacement data, meaning that the output
data might be longer than the input.
The cut
and delete
subcommands require a position
as an argument. This has
the following format:
<begin> Begin to the end of input
<begin>:<end> Begin to end (exclusive), requires <end> > <begin>
Example: 'foobar', 0:2 == 'fo' or 3:5 == 'ba'
<begin>:=<end> Begin to end (inclusive), requires <end> > <begin>
Example: 'foobar', 0:=2 == 'foo' or 3:=5 == 'bar'
<begin>+<count> Begin plus <count> (exclusive), requires <count> > 0.
The length includes the begin position: 0+10 is 10 bytes, from 0..9 (same as 0:9)
sed
if one remembers the syntax.Copyright (c) 2020 - Armin Widegreen
bytie
is licensed under the 3-Clause BSD License (3-Clause BSD or
https://opensource.org/licenses/BSD-3-Clause)