Browse files

Add two ListObjects examples, including a streaming XML parser example

  • Loading branch information...
1 parent a54c798 commit b450764355b19b94289c7d92aa835add004c2539 @chilts committed Apr 11, 2013
Showing with 52 additions and 0 deletions.
  1. +17 −0 examples/ListObjects-01-Basic.js
  2. +35 −0 examples/ListObjects-02-StreamIntoSax.js
View
17 examples/ListObjects-01-Basic.js
@@ -0,0 +1,17 @@
+var dump = require('./dump.js');
+var amazonS3 = require('../awssum-amazon-s3.js');
+
+var s3 = new amazonS3.S3({
+ 'accessKeyId' : process.env.ACCESS_KEY_ID,
+ 'secretAccessKey' : process.env.SECRET_ACCESS_KEY,
+ 'region' : amazonS3.US_EAST_1,
+});
+
+var options = {
+ BucketName : 'pie-17',
+};
+
+s3.ListObjects(options, function(err, data) {
+ dump(err, 'err');
+ dump(data, 'data');
+});
View
35 examples/ListObjects-02-StreamIntoSax.js
@@ -0,0 +1,35 @@
+var dump = require('./dump.js');
+var amazonS3 = require('../awssum-amazon-s3.js');
+var sax = require('sax');
+
+var s3 = new amazonS3.S3({
+ 'accessKeyId' : process.env.ACCESS_KEY_ID,
+ 'secretAccessKey' : process.env.SECRET_ACCESS_KEY,
+ 'region' : amazonS3.US_EAST_1,
+});
+
+var options = {
+ BucketName : 'pie-17',
+};
+
+s3.ListObjects(options, { stream : true }, function(err, data) {
+ dump(err, 'err');
+
+ if ( !err ) {
+ var lastText;
+
+ // set up the XML parser
+ var parser = sax.createStream(false);
+ parser.on('text', function (t) {
+ lastText = t;
+ });
+ parser.on("closetag", function(tag) {
+ if ( tag === 'KEY' ) {
+ console.log('* ' + lastText);
+ }
+ });
+
+ // pipe the XML stream into the parser
+ data.Stream.pipe(parser);
+ }
+});

0 comments on commit b450764

Please sign in to comment.