From 3327210cd07bd2656f9e52a4a1ee75ff4309e32c Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 16 Nov 2023 13:26:01 +0200 Subject: [PATCH] initial commit --- .gitignore | 1 + README.md | 31 +++++++++++++- data/export/test.txt | 1 + drivers/kevacoin/get.php | 87 ++++++++++++++++++++++++++++++++++++++++ drivers/kevacoin/put.php | 64 +++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 data/export/test.txt create mode 100644 drivers/kevacoin/get.php create mode 100644 drivers/kevacoin/put.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ab21d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/import/* \ No newline at end of file diff --git a/README.md b/README.md index ff34425..7223663 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,31 @@ # clitor -CLI util to put & get large objects in small block size + +CLI util to operate with large objects in small blocks size + +## drivers + + * [x] [kevacoin](https://github.com/kevacoin-project/kevacoin) + +### put + +export FS object to blockchain namespace + +``` +php driver/put.php processor filename [length] +``` + +* `processor` - path to kevacoin-cli +* `filename` - file path to store in blockchain +* `length` - optional split size, 3072 bytes [max](https://kevacoin.org/faq.html) + +### get + +import namespace to FS location + +``` +php driver/get.php processor namespace [destination] +``` + +* `processor` - path to kevacoin-cli +* `namespace` - hash received from the `put` command +* `destination` - optional file system location, `data/import` by default \ No newline at end of file diff --git a/data/export/test.txt b/data/export/test.txt new file mode 100644 index 0000000..f3a3485 --- /dev/null +++ b/data/export/test.txt @@ -0,0 +1 @@ +text \ No newline at end of file diff --git a/drivers/kevacoin/get.php b/drivers/kevacoin/get.php new file mode 100644 index 0000000..9f1233e --- /dev/null +++ b/drivers/kevacoin/get.php @@ -0,0 +1,87 @@ +height] = $ns->value; +} + +krsort($names); + +// Get namespace content +$parts = _exec( + $argv[1], + sprintf( + '%s %s "\d+"', + 'keva_filter', + $argv[2] + ) +); + +print_r($parts); + +// Merge content data +$data = []; +foreach ($parts as $part) +{ + $data[$part->key] = $part->value; +} + +ksort($data); + +// Save merged data to destination +$filename = isset($argv[3]) ? $argv[3] : sprintf( + '%s/../../data/import/kevacoin.%s.%s', + __DIR__, + $argv[2], + $names[array_key_first($names)] +); + +file_put_contents( + $filename, + base64_decode( + implode('', $data) + ) +); + +echo sprintf( + 'saved to %s' . PHP_EOL, + $filename +); \ No newline at end of file diff --git a/drivers/kevacoin/put.php b/drivers/kevacoin/put.php new file mode 100644 index 0000000..2222322 --- /dev/null +++ b/drivers/kevacoin/put.php @@ -0,0 +1,64 @@ +namespaceId)) +{ + $parts = str_split( + base64_encode( + file_get_contents($argv[2]) + ), + isset($argv[3]) && $argv[3] <= 3072 ? (int) $argv[3] : 3072 // 3072 bytes limit + ); + + foreach ($parts as $key => $value) + { + $kevaPut = _exec( + $argv[1], + sprintf( + '%s %s %s %s', + 'keva_put', + $kevaNamespace->namespaceId, + $key, + $value + ) + ); + + print_r($kevaPut); + } +} \ No newline at end of file