s3p 3.3.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -12,8 +12,8 @@ Added common copy options:
|
|
|
12
12
|
must be applied to obtain the media-type referenced by the Content-Type header field.
|
|
13
13
|
- `--content-language string` The language the content is in.
|
|
14
14
|
- `--content-type string` A standard MIME type describing the format of the object data.
|
|
15
|
-
- `--expires date-time` The date and time at which the object is no longer cacheable. e.g. `js:new Date` or `Wed Dec 31 1969
|
|
16
|
-
16:00:00 GMT-0800 (PST)` or `123456789`
|
|
15
|
+
- `--expires date-time` The date and time at which the object is no longer cacheable. e.g. `"js:new Date"` or `"Wed Dec 31 1969
|
|
16
|
+
16:00:00 GMT-0800 (PST)"` or `123456789`
|
|
17
17
|
- `--request-payer string` Confirms that the requester knows that they will be charged for the request. Bucket owners need not
|
|
18
18
|
specify this parameter in their requests.
|
|
19
19
|
- `--storage-class string` By default, Amazon S3 uses the STANDARD Storage Class to store newly created objects. The STANDARD
|
|
@@ -24,4 +24,4 @@ Added common copy options:
|
|
|
24
24
|
|
|
25
25
|
# 3.1
|
|
26
26
|
|
|
27
|
-
Added the programmatic API. See the [README](
|
|
27
|
+
Added the programmatic API. See the [README](README.md#API).
|
package/README.md
CHANGED
|
@@ -101,14 +101,14 @@ shane@genui.com
|
|
|
101
101
|
|
|
102
102
|
# Documentation
|
|
103
103
|
|
|
104
|
-
All the documentation is embedded in the CLI
|
|
104
|
+
All the documentation is embedded in the CLI help pages. Use:
|
|
105
105
|
|
|
106
106
|
```shell
|
|
107
107
|
# get a list of commands
|
|
108
108
|
npx s3p help
|
|
109
109
|
|
|
110
110
|
# get a list of options for a command
|
|
111
|
-
#
|
|
111
|
+
# example:
|
|
112
112
|
npx s3p cp --help
|
|
113
113
|
```
|
|
114
114
|
|
|
@@ -116,17 +116,18 @@ npx s3p cp --help
|
|
|
116
116
|
|
|
117
117
|
All the capabilities of the CLI are also available as an API. To learn the API, first learn the CLI options, and then, to learn the API call for a specific CLI command, run that command on the command-line with the `--api-example` option. This will output example JavaScript code for invoking that command programmatically.
|
|
118
118
|
|
|
119
|
-
> NOTE: When you use `--api-example`
|
|
119
|
+
> NOTE: When you use `--api-example` on the command-line, your command won't actually run. S3P will *only* output the JavaScript equivalent of the CLI command to the console and then quit.
|
|
120
120
|
|
|
121
121
|
### Example
|
|
122
122
|
Run:
|
|
123
123
|
|
|
124
124
|
```shell
|
|
125
|
-
> npx s3p ls --bucket --quiet --api-example
|
|
125
|
+
> npx s3p ls --bucket foo --quiet --api-example
|
|
126
126
|
```
|
|
127
127
|
Output:
|
|
128
128
|
```javascript
|
|
129
|
-
require('s3p').
|
|
129
|
+
require('s3p').ls({
|
|
130
|
+
bucket: "foo",
|
|
130
131
|
quiet: true
|
|
131
132
|
})
|
|
132
133
|
// > Promise
|
|
@@ -139,6 +140,7 @@ Test run:
|
|
|
139
140
|
Paste:
|
|
140
141
|
```javascript
|
|
141
142
|
require('s3p').listBuckets({
|
|
143
|
+
bucket: "foo",
|
|
142
144
|
quiet: true
|
|
143
145
|
}).then((out) => console.log(out));
|
|
144
146
|
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
let Caf = require('caffeine-script-runtime');
|
|
3
|
-
Caf.defMod(module, () => {return Caf.importInvoke(["BaseClass", "shellEscape", "lowerCamelCase", "currentSecond", "log", "Array", "Error", "merge", "
|
|
3
|
+
Caf.defMod(module, () => {return Caf.importInvoke(["BaseClass", "shellEscape", "lowerCamelCase", "currentSecond", "log", "Array", "Error", "merge", "path", "timeout", "createWriteStreamSafe", "Promise", "compactFlatten", "createS3Url", "shellExec", "dashCase", "isFunction", "present"], [global, require('../StandardImport'), require('./FsEasy'), require('./LibMisc'), {shellEscape: require('shell-escape'), promisify: require('util').promisify, fs: require('fs'), path: require('path')}], (BaseClass, shellEscape, lowerCamelCase, currentSecond, log, Array, Error, merge, path, timeout, createWriteStreamSafe, Promise, compactFlatten, createS3Url, shellExec, dashCase, isFunction, present) => {let escape, S3; escape = function(single) {return shellEscape([single]);}; require('aws-sdk').config.setPromisesDependency(require('bluebird')); return S3 = Caf.defClass(class S3 extends BaseClass {}, function(S3, classSuper, instanceSuper) {this.awsSdkS3 = new (require('aws-sdk').S3)({}); this.classGetter({s3: function() {return this.awsSdkS3;}}); this.commonCopyOptionsSdkKeys = ["ACL", "CacheControl", "ContentDisposition", "ContentEncoding", "ContentLanguage", "ContentType", "Expires", "RequestPayer", "StorageClass"]; this.commonSdkCopyOptionsByLowerCamelCaseKeys = Caf.object(this.commonCopyOptionsSdkKeys, null, null, null, (k) => lowerCamelCase(k)); this.listBuckets = () => this.s3.listBuckets().promise().then(({Buckets}) => Caf.object(Buckets, ({Name, CreationDate}) => CreationDate, null, null, ({Name, CreationDate}) => Name)); this.list = ({bucket, prefix, limit = 1000, startAfter}) => {let startTime; startTime = currentSecond(); return this.s3.listObjectsV2({Bucket: bucket, Prefix: prefix, MaxKeys: limit, StartAfter: startAfter, FetchOwner: true}).promise().tapCatch((error) => log.error({"S3.list-error": {bucket, prefix, startAfter, limit, error}})).then((results) => {let duration; duration = currentSecond() - startTime; if (!(Caf.is(results.Contents, Array))) {log.warn({"S3.list-no-Contents": {bucket, prefix, startAfter, limit, duration, results}}); throw new Error("S3.list: Contents is not an array");} else {if (duration > 60) {log.warn({"S3.list-slow": {bucket, prefix, startAfter, limit, duration, results: merge(results, {Contents: `Array ${Caf.toString(results.Contents.length)}`})}});};}; return results.Contents;});}; this.copy = (options) => {let largeCopyThreshold, scratchState, copyScratchState, fromBucket, toBucket, fromKey, toKey, size, toFolder, pretend, verbose, copyOptions, toLocalFile, temp, temp1; if ((largeCopyThreshold = options.largeCopyThreshold, scratchState = options.scratchState)) {copyScratchState = ((temp = scratchState.copyScratchState) != null ? temp : scratchState.copyScratchState = {});}; temp1 = this._normalizeCopyOptions(options); fromBucket = temp1.fromBucket; toBucket = temp1.toBucket; fromKey = temp1.fromKey; toKey = temp1.toKey; size = temp1.size; toFolder = temp1.toFolder; pretend = temp1.pretend; verbose = temp1.verbose; return (size >= largeCopyThreshold || /\s/.test(toKey)) ? this.largeCopy({commonCopyOptions: this.extractCommonCopyOptions(options), fromBucket, toBucket, toFolder, fromKey, toKey, pretend, verbose}) : (copyOptions = merge(toFolder ? {Bucket: fromBucket, Key: fromKey} : {CopySource: `${Caf.toString(fromBucket)}/${Caf.toString(fromKey)}`, Bucket: toBucket, Key: toKey}, this._getCommonCopyOptionsForSdk(options)), toLocalFile = toFolder ? path.join(toFolder, toKey) : undefined, verbose ? log.unquoted(merge({copyObject: copyOptions, toLocalFile})) : undefined, pretend ? timeout(1, () => {return {pretend: true};}) : toFolder ? createWriteStreamSafe(toLocalFile, copyScratchState).then((writeStream) => new Promise((resolve, reject) => this.s3.getObject(copyOptions).createReadStream().pipe(writeStream).on("finish", resolve).on("error", reject))) : this.s3.copyObject(copyOptions).promise());}; this.delete = (options) => this.s3.deleteObject({Bucket: options.bucket, Key: options.key}); this.largeCopy = (options) => {let commonCopyOptions, fromBucket, fromFolder, toBucket, toFolder, fromKey, toKey, pretend, verbose, command, temp; commonCopyOptions = options.commonCopyOptions; temp = this._normalizeCopyOptions(options); fromBucket = temp.fromBucket; fromFolder = temp.fromFolder; toBucket = temp.toBucket; toFolder = temp.toFolder; fromKey = temp.fromKey; toKey = temp.toKey; pretend = temp.pretend; verbose = temp.verbose; command = compactFlatten([`aws s3 cp ${Caf.toString(escape(createS3Url(fromBucket, fromFolder, fromKey)))} ${Caf.toString(escape(createS3Url(toBucket, toFolder, toKey)))}`, Caf.array(commonCopyOptions, (v, key) => `--${Caf.toString(dashCase(key))} ${Caf.toString((() => {switch (v) {case true: return ""; default: return escape(v);};})())}`, (v, key) => v)]).join(" "); if (verbose) {log.unquoted({largeCopy: command});}; return pretend ? timeout(1, () => {return {pretend: true};}) : shellExec(command);}; this.headObject = ({bucket, key}) => this.s3.headObject({Bucket: bucket, Key: key}).promise(); this._normalizeCopyOptions = function(options) {let bucket, key, fromBucket, toBucket, fromKey, toKey, size, temp, temp1, temp2, temp3; bucket = options.bucket; key = options.key; fromBucket = (undefined !== (temp = options.fromBucket)) ? temp : bucket; toBucket = (undefined !== (temp1 = options.toBucket)) ? temp1 : bucket; fromKey = (undefined !== (temp2 = options.fromKey)) ? temp2 : key; toKey = (undefined !== (temp3 = options.toKey)) ? temp3 : key; size = options.size; if (isFunction(toKey)) {toKey = toKey(fromKey, fromBucket, toBucket, options.size);}; if (!(present(fromBucket) && present(toBucket) && present(fromKey) && present(toKey))) {throw new Error("Missing one of: fromBucket, toBucket, fromKey, toKey or bucket or key as a default");}; return merge(options, {fromBucket, fromKey, toBucket, toKey});}; this._getCommonCopyOptionsForSdk = (options) => Caf.object(this.commonSdkCopyOptionsByLowerCamelCaseKeys, (sdkKey, lowerCamelCasedKey) => options[lowerCamelCasedKey], null, null, (sdkKey, lowerCamelCasedKey) => sdkKey); this.extractCommonCopyOptions = (options) => Caf.object(this.commonSdkCopyOptionsByLowerCamelCaseKeys, (v, k) => options[k]); this.shouldSyncObjects = function(options) {let fromBucket, toBucket, fromKey, toKey, temp; temp = this._normalizeCopyOptions(options); fromBucket = temp.fromBucket; toBucket = temp.toBucket; fromKey = temp.fromKey; toKey = temp.toKey; return Promise.then(() => (options.size < Caf.pow(1024, 2) || !options.size) ? true : this.headObject(options).then(({ContentLength}) => ContentLength !== options.size));}; this.syncObject = (options) => this.shouldSyncObjects(options).then((shouldSync) => shouldSync ? this.copyObject(options).then((result) => merge(result, {copied: true})) : {copied: false});});});});
|
|
4
4
|
//# sourceMappingURL=S3.js.map
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
"source/S3Parallel/Lib/S3.caf"
|
|
7
7
|
],
|
|
8
8
|
"names": [],
|
|
9
|
-
"mappings": "AAAA;;AAAA,wSAAO,8BAAiB,qBAAS,uBAAa,sCAAc,sCAAiB,mBAAK,qPAClF,SAAM,QAAG,CAAC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YACZ,uBAAmB,cACb,CAAC,eACF,aACD,gBAAY,cACN,CAAC,WAAW,MAAM,SAAQ,QAAQ,UAErC,CAAG,QAAQ"
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -37,6 +37,7 @@ class S3 extends BaseClass
|
|
|
37
37
|
Prefix: prefix
|
|
38
38
|
MaxKeys: limit
|
|
39
39
|
StartAfter: startAfter
|
|
40
|
+
FetchOwner: true
|
|
40
41
|
.promise()
|
|
41
42
|
.tapCatch (error) ->
|
|
42
43
|
log.error S3.list-error: {} bucket, prefix, startAfter, limit, error
|
|
@@ -101,14 +102,19 @@ class S3 extends BaseClass
|
|
|
101
102
|
|
|
102
103
|
@_getCommonCopyOptionsForSdk options
|
|
103
104
|
|
|
105
|
+
toLocalFile = if toFolder then path.join toFolder, toKey
|
|
106
|
+
|
|
104
107
|
if verbose
|
|
105
|
-
log.unquoted
|
|
108
|
+
log.unquoted merge {}
|
|
109
|
+
copyObject: copyOptions
|
|
110
|
+
toLocalFile
|
|
106
111
|
|
|
107
112
|
if pretend
|
|
108
113
|
timeout 1 -> pretend: true
|
|
114
|
+
|
|
109
115
|
else if toFolder
|
|
110
116
|
createWriteStreamSafe
|
|
111
|
-
|
|
117
|
+
toLocalFile
|
|
112
118
|
copyScratchState
|
|
113
119
|
|
|
114
120
|
.then (writeStream) -> new Promise (resolve, reject) ->
|