-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk_db.sh
29 lines (24 loc) · 844 Bytes
/
chunk_db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# https://github.com/phiresky/sql.js-httpvfs/blob/master/create_db.sh
set -eu
indb="$1"
outdir="$2"
# for chunked mode, we need to know the database size in bytes beforehand
bytes="$(stat --printf="%s" "$indb")"
# set chunk size to 10MiB (needs to be a multiple of the `pragma page_size`!)
serverChunkSize=$((25 * 1024 * 1024))
suffixLength=3
rm -f "$outdir/tp."*
split "$indb" --bytes=$serverChunkSize "$outdir/tp." --suffix-length=$suffixLength --numeric-suffixes
# set request chunk size to match page size
requestChunkSize="$(sqlite3 "$indb" 'pragma page_size')"
# write a json config
echo '
{
"serverMode": "chunked",
"requestChunkSize": '$requestChunkSize',
"databaseLengthBytes": '$bytes',
"serverChunkSize": '$serverChunkSize',
"urlPrefix": "tp.",
"suffixLength": '$suffixLength'
}
' >"$outdir/config.json"