tuning splitter

This commit is contained in:
Ville Rantanen
2018-02-24 09:40:20 +02:00
parent c0dbe045ec
commit 525070fe23

View File

@@ -134,7 +134,7 @@ def upload_join_splitted(name, password):
for part in range(100):
filename = os.path.join(
share['path'],
"%s.part.%02d"%(
"%s.part.%03d"%(
request.form['filename'],
part
)
@@ -456,35 +456,38 @@ def script_upload_split(name = None, password = None):
return "Upload not allowed",400
return """#!/bin/bash
test -n "$1" || {
echo "First argument is split size in megabytes, add files to upload as next arguments"
exit 1
}
test -n "$2" || {
echo "Add files to upload as argument"
echo "Usage: [-s SplitMegabytes] file/folder [files/folders]"
exit 1
}
MAXBYTES=$(( 512 * 1024 * 1024 ))
for (( i=1; i<=$#; i++ )); do
j=$(( $i + 1 ))
[[ ${!i} = "-s" ]] && {
MAXBYTES=$(( ${!j} * 1024 * 1024 ))
shift 2
}
done
CAT=$( which cat )
which pv &> /dev/null && CAT=$( which pv )
ROOTURL="%s"
SHARE="%s"
TOKEN="%s"
MAXBYTES=$(( $1 * 1024 * 1024 ))
shift 1
send_file() {
$CAT "$file_name" | split -d -b $MAXBYTES \
--filter="curl -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \
- "$base_name.part."
curl -F "filename=$base_name" ${ROOTURL}upload_join/${SHARE}/${TOKEN}
$CAT "$file_name" | split -d -a 3 -b $MAXBYTES \
--filter="curl -f -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \
- "$base_name.part." && \
curl -F "filename=$base_name" ${ROOTURL}upload_join/${SHARE}/${TOKEN}
}
send_folder() {
which pv &> /dev/null && printf -v dusize -- "--size %%dk" $( du -s -k "$file_name" | cut -f1 )
tar c "$file_name" | $CAT $dusize - | split -d -b $MAXBYTES \
--filter="curl -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \
- "$base_name.tgz.part."
curl -F "filename=$base_name.tgz" ${ROOTURL}upload_join/${SHARE}/${TOKEN}
tar c "$file_name" | $CAT $dusize - | split -d -a 3 -b $MAXBYTES \
--filter="curl -f -F \\"file=@-;filename=\${FILE}\\" ${ROOTURL}upload/${SHARE}/${TOKEN}" \
- "$base_name.tar.part." && \
curl -F "filename=$base_name.tar" ${ROOTURL}upload_join/${SHARE}/${TOKEN}
}
echo "Splitting to $(( $MAXBYTES / 1024 / 1024 )) Mb chunks"
for file_name in "$@"; do
base_name=$( basename "$file_name" )
test -f "$file_name" && {