Skip to content

Commit

Permalink
new: Overhaul generate-large-binary-resource.sh
Browse files Browse the repository at this point in the history
Thank you, GAI!
  • Loading branch information
allentiak committed Oct 22, 2024
1 parent 4acd600 commit 5024e41
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions .github/scripts/generate-large-binary-resource.sh
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

0 comments on commit 5024e41

Please sign in to comment.