Skip to content

Instantly share code, notes, and snippets.

@JonathanSmith
Last active August 29, 2015 14:04
Show Gist options
  • Save JonathanSmith/442185b6fa09d749e0c6 to your computer and use it in GitHub Desktop.
Save JonathanSmith/442185b6fa09d749e0c6 to your computer and use it in GitHub Desktop.
testcase.sh
#!/bin/bash
PEMFILEPATH=$1
DEV_EMAIL=$2
BUCKET=$3
echo "CREATING 200MB Random File";
dd if=/dev/urandom of=file.in bs=1M count=1
echo "FINISHED CREATING 1MB Random File"
echo "$(ls -ltra file.in)"
cat <<EOF > testcase.js
var gcloud = require("gcloud");
var bucket = new gcloud.storage.Bucket({pemFilePath: "$PEMFILEPATH",
email: "$DEV_EMAIL",
bucketName: "$BUCKET"});
bucket.writeFile("file.in","file.in",function(err) {
if (err){
console.log("Error: %s", err);
console.log("Stacktrace: %s", err.stack);
process.exit(1);
}
console.log("completed file transfer");
bucket.stat("file.in", function(err, metadata) {
if (err){
console.log("Error: %s", err);
console.log("Stacktrace: %s", err.stack);
process.exit(1);
}
console.log("File Stats: %s", JSON.stringify(metadata));
process.exit(0);
});
});
EOF
node testcase.js
@JonathanSmith
Copy link
Author

jsmith@localhost gcloud-node]$ sh testcase.sh [credentials redacted]
CREATING 1MB Random File
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.138507 s, 7.6 MB/s
FINISHED CREATING 200MB Random File
-rw-rw-r-- 1 jsmith jsmith 1048576 Jul 23 13:58 file.in
completed file transfer
File Stats: {"kind":"storage#object","id":"tervelabucket/file.in/1406138330037000","selfLink":"https://www.googleapis.com/storage/v1/b/tervelabucket/o/file.in","name":"file.in","bucket":"tervelabucket","generation":"1406138330037000","metageneration":"1","contentType":"text/plain","updated":"2014-07-23T17:58:50.036Z","storageClass":"STANDARD","size":"1048577","md5Hash":"kbavLECUbJsCQJMgTA/ZMQ==","mediaLink":"https://www.googleapis.com/download/storage/v1/b/tervelabucket/o/file.in?generation=1406138330037000&alt=media","owner":{"entity":"user-00b4903a9719c8ab7bcf621734f2ff68b2e57e05ce8beaaff597bdf5f9bf2e0c","entityId":"00b4903a9719c8ab7bcf621734f2ff68b2e57e05ce8beaaff597bdf5f9bf2e0c"},"crc32c":"sKD5eQ==","etag":"CIj2qr2B3L8CEAE="}
[jsmith@localhost gcloud-node]$ ll
total 1072

@JonathanSmith
Copy link
Author

Check size in 'stat' call vs. size as described from ll, there is 1 extra byte in the version uploaded to the cloud.
Downloading the uploaded file and running them both through hexdump -C and then doing a diff of the hexdump outputs shows that there is an extra 0A (newline) at the end of the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment