-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Overhaul
generate-large-binary-resource.sh
Thank you, GAI!
- Loading branch information
Showing
1 changed file
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
#!/bin/bash -e | ||
|
||
# generate 8 MiB random data as Base64 | ||
DATA=$(openssl rand -base64 8388608) | ||
generate_random_data() { | ||
# Default size: 8 MiB | ||
local size=${1:-8388608} | ||
openssl rand -base64 "$size" | ||
} | ||
|
||
echo "{\"resourceType\": \"Binary\", \"data\": \"$DATA\"}" > large-binary.json | ||
echo "<Binary xmlns=\"http://hl7.org/fhir\"><data value=\"$DATA\"/></Binary>" > large-binary.xml | ||
create_data_string() { | ||
local data=${1:-""} | ||
local type=${2:-""} | ||
|
||
if [[ -z "$data" ]]; then | ||
echo "Error: No data provided for string creation." | ||
return 1 | ||
fi | ||
|
||
case "$type" in | ||
json) | ||
echo "{\"resourceType\": \"Binary\", \"data\": \"$data\"}" | ||
;; | ||
xml) | ||
echo "<Binary xmlns=\"http://hl7.org/fhir\"><data value=\"$data\"/></Binary>" | ||
;; | ||
*) | ||
echo "Error: Unsupported type '$type'. Use 'json' or 'xml'." | ||
return 1 | ||
;; | ||
esac | ||
} | ||
|
||
write_to_file() { | ||
local output=${1} | ||
local filename=${2} | ||
|
||
if [[ -z "$output" || -z "$filename" ]]; then | ||
echo "Error: output or filename cannot be empty." | ||
return 1 | ||
fi | ||
|
||
echo "$output" > "$filename" | ||
} | ||
|
||
main() { | ||
local data_size=8388608 # 8 MiB | ||
local random_data=$(generate_random_data "$data_size") | ||
|
||
local json_output=$(create_data_string "$random_data" "json") | ||
local xml_output=$(create_data_string "$random_data" "xml") | ||
|
||
write_to_file "$json_output" "large-binary.json" | ||
write_to_file "$xml_output" "large-binary.xml" | ||
} | ||
|
||
main |