protobufjs 6.8.8 → 6.8.9
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/LICENSE +39 -39
- package/README.md +879 -879
- package/cli/LICENSE +33 -33
- package/cli/README.md +11 -11
- package/cli/index.d.ts +3 -3
- package/cli/index.js +3 -3
- package/cli/lib/tsd-jsdoc/LICENSE +20 -20
- package/cli/lib/tsd-jsdoc/README.md +23 -23
- package/cli/lib/tsd-jsdoc/plugin.js +21 -21
- package/cli/lib/tsd-jsdoc/publish.js +693 -693
- package/cli/lib/tsd-jsdoc.json +18 -18
- package/cli/package.standalone.json +31 -31
- package/cli/pbjs.d.ts +9 -9
- package/cli/pbjs.js +329 -329
- package/cli/pbts.d.ts +9 -9
- package/cli/pbts.js +197 -197
- package/cli/targets/json-module.js +38 -38
- package/cli/targets/json.js +8 -8
- package/cli/targets/proto.js +326 -326
- package/cli/targets/proto2.js +10 -10
- package/cli/targets/proto3.js +10 -10
- package/cli/targets/static-module.js +29 -29
- package/cli/targets/static.js +702 -702
- package/cli/util.js +183 -183
- package/cli/wrappers/amd.js +7 -7
- package/cli/wrappers/closure.js +7 -7
- package/cli/wrappers/commonjs.js +7 -7
- package/cli/wrappers/default.js +15 -15
- package/cli/wrappers/es6.js +5 -5
- package/dist/README.md +31 -31
- package/dist/light/README.md +31 -31
- package/dist/light/protobuf.js +6030 -6030
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +1 -1
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/README.md +31 -31
- package/dist/minimal/protobuf.js +1876 -1876
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +1 -1
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +7595 -7595
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +1 -1
- package/dist/protobuf.min.js.map +1 -1
- package/ext/debug/README.md +4 -4
- package/ext/debug/index.js +71 -71
- package/ext/descriptor/README.md +72 -72
- package/ext/descriptor/index.js +1052 -1052
- package/ext/descriptor/test.js +54 -54
- package/google/LICENSE +27 -27
- package/google/README.md +1 -1
- package/google/api/annotations.proto +10 -10
- package/google/protobuf/descriptor.proto +286 -286
- package/google/protobuf/source_context.proto +7 -7
- package/index.js +4 -4
- package/light.d.ts +2 -2
- package/light.js +3 -3
- package/minimal.d.ts +2 -2
- package/minimal.js +4 -4
- package/package-lock.json +1748 -642
- package/package.json +119 -122
- package/scripts/changelog.js +150 -150
- package/scripts/postinstall.js +35 -35
- package/src/common.js +399 -399
- package/src/converter.js +293 -293
- package/src/decoder.js +106 -106
- package/src/encoder.js +99 -99
- package/src/enum.js +181 -181
- package/src/field.js +371 -371
- package/src/index-light.js +104 -104
- package/src/index-minimal.js +36 -36
- package/src/index.js +12 -12
- package/src/mapfield.js +126 -126
- package/src/message.js +138 -138
- package/src/method.js +151 -151
- package/src/namespace.js +433 -433
- package/src/object.js +200 -200
- package/src/oneof.js +203 -203
- package/src/parse.js +758 -758
- package/src/reader.js +405 -405
- package/src/reader_buffer.js +44 -44
- package/src/root.js +351 -351
- package/src/roots.js +18 -18
- package/src/rpc/service.js +142 -142
- package/src/rpc.js +36 -36
- package/src/service.js +167 -167
- package/src/tokenize.js +397 -397
- package/src/type.js +589 -589
- package/src/types.js +196 -196
- package/src/typescript.jsdoc +15 -15
- package/src/util/longbits.js +200 -200
- package/src/util/minimal.js +414 -414
- package/src/util.js +178 -178
- package/src/verifier.js +176 -176
- package/src/wrappers.js +83 -83
- package/src/writer.js +459 -459
- package/src/writer_buffer.js +81 -81
- package/tsconfig.json +6 -6
- package/cli/node_modules/os-tmpdir/index.js +0 -25
- package/cli/node_modules/os-tmpdir/license +0 -21
- package/cli/node_modules/os-tmpdir/readme.md +0 -32
- package/cli/node_modules/tmp/LICENSE +0 -21
- package/cli/node_modules/tmp/README.md +0 -314
- package/cli/node_modules/tmp/lib/tmp.js +0 -611
package/src/writer_buffer.js
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = BufferWriter;
|
|
3
|
-
|
|
4
|
-
// extends Writer
|
|
5
|
-
var Writer = require("./writer");
|
|
6
|
-
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
|
|
7
|
-
|
|
8
|
-
var util = require("./util/minimal");
|
|
9
|
-
|
|
10
|
-
var Buffer = util.Buffer;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Constructs a new buffer writer instance.
|
|
14
|
-
* @classdesc Wire format writer using node buffers.
|
|
15
|
-
* @extends Writer
|
|
16
|
-
* @constructor
|
|
17
|
-
*/
|
|
18
|
-
function BufferWriter() {
|
|
19
|
-
Writer.call(this);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Allocates a buffer of the specified size.
|
|
24
|
-
* @param {number} size Buffer size
|
|
25
|
-
* @returns {Buffer} Buffer
|
|
26
|
-
*/
|
|
27
|
-
BufferWriter.alloc = function alloc_buffer(size) {
|
|
28
|
-
return (BufferWriter.alloc = util._Buffer_allocUnsafe)(size);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
|
|
32
|
-
? function writeBytesBuffer_set(val, buf, pos) {
|
|
33
|
-
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
|
34
|
-
// also works for plain array values
|
|
35
|
-
}
|
|
36
|
-
/* istanbul ignore next */
|
|
37
|
-
: function writeBytesBuffer_copy(val, buf, pos) {
|
|
38
|
-
if (val.copy) // Buffer values
|
|
39
|
-
val.copy(buf, pos, 0, val.length);
|
|
40
|
-
else for (var i = 0; i < val.length;) // plain array values
|
|
41
|
-
buf[pos++] = val[i++];
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @override
|
|
46
|
-
*/
|
|
47
|
-
BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
48
|
-
if (util.isString(value))
|
|
49
|
-
value = util._Buffer_from(value, "base64");
|
|
50
|
-
var len = value.length >>> 0;
|
|
51
|
-
this.uint32(len);
|
|
52
|
-
if (len)
|
|
53
|
-
this._push(writeBytesBuffer, len, value);
|
|
54
|
-
return this;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function writeStringBuffer(val, buf, pos) {
|
|
58
|
-
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
59
|
-
util.utf8.write(val, buf, pos);
|
|
60
|
-
else
|
|
61
|
-
buf.utf8Write(val, pos);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @override
|
|
66
|
-
*/
|
|
67
|
-
BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
68
|
-
var len = Buffer.byteLength(value);
|
|
69
|
-
this.uint32(len);
|
|
70
|
-
if (len)
|
|
71
|
-
this._push(writeStringBuffer, len, value);
|
|
72
|
-
return this;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Finishes the write operation.
|
|
78
|
-
* @name BufferWriter#finish
|
|
79
|
-
* @function
|
|
80
|
-
* @returns {Buffer} Finished buffer
|
|
81
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = BufferWriter;
|
|
3
|
+
|
|
4
|
+
// extends Writer
|
|
5
|
+
var Writer = require("./writer");
|
|
6
|
+
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
|
|
7
|
+
|
|
8
|
+
var util = require("./util/minimal");
|
|
9
|
+
|
|
10
|
+
var Buffer = util.Buffer;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a new buffer writer instance.
|
|
14
|
+
* @classdesc Wire format writer using node buffers.
|
|
15
|
+
* @extends Writer
|
|
16
|
+
* @constructor
|
|
17
|
+
*/
|
|
18
|
+
function BufferWriter() {
|
|
19
|
+
Writer.call(this);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Allocates a buffer of the specified size.
|
|
24
|
+
* @param {number} size Buffer size
|
|
25
|
+
* @returns {Buffer} Buffer
|
|
26
|
+
*/
|
|
27
|
+
BufferWriter.alloc = function alloc_buffer(size) {
|
|
28
|
+
return (BufferWriter.alloc = util._Buffer_allocUnsafe)(size);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
|
|
32
|
+
? function writeBytesBuffer_set(val, buf, pos) {
|
|
33
|
+
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
|
34
|
+
// also works for plain array values
|
|
35
|
+
}
|
|
36
|
+
/* istanbul ignore next */
|
|
37
|
+
: function writeBytesBuffer_copy(val, buf, pos) {
|
|
38
|
+
if (val.copy) // Buffer values
|
|
39
|
+
val.copy(buf, pos, 0, val.length);
|
|
40
|
+
else for (var i = 0; i < val.length;) // plain array values
|
|
41
|
+
buf[pos++] = val[i++];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @override
|
|
46
|
+
*/
|
|
47
|
+
BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
48
|
+
if (util.isString(value))
|
|
49
|
+
value = util._Buffer_from(value, "base64");
|
|
50
|
+
var len = value.length >>> 0;
|
|
51
|
+
this.uint32(len);
|
|
52
|
+
if (len)
|
|
53
|
+
this._push(writeBytesBuffer, len, value);
|
|
54
|
+
return this;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
function writeStringBuffer(val, buf, pos) {
|
|
58
|
+
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
59
|
+
util.utf8.write(val, buf, pos);
|
|
60
|
+
else
|
|
61
|
+
buf.utf8Write(val, pos);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @override
|
|
66
|
+
*/
|
|
67
|
+
BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
68
|
+
var len = Buffer.byteLength(value);
|
|
69
|
+
this.uint32(len);
|
|
70
|
+
if (len)
|
|
71
|
+
this._push(writeStringBuffer, len, value);
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Finishes the write operation.
|
|
78
|
+
* @name BufferWriter#finish
|
|
79
|
+
* @function
|
|
80
|
+
* @returns {Buffer} Finished buffer
|
|
81
|
+
*/
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES5",
|
|
4
|
-
"experimentalDecorators": true,
|
|
5
|
-
"emitDecoratorMetadata": true
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"experimentalDecorators": true,
|
|
5
|
+
"emitDecoratorMetadata": true
|
|
6
|
+
}
|
|
7
7
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var isWindows = process.platform === 'win32';
|
|
3
|
-
var trailingSlashRe = isWindows ? /[^:]\\$/ : /.\/$/;
|
|
4
|
-
|
|
5
|
-
// https://github.com/nodejs/node/blob/3e7a14381497a3b73dda68d05b5130563cdab420/lib/os.js#L25-L43
|
|
6
|
-
module.exports = function () {
|
|
7
|
-
var path;
|
|
8
|
-
|
|
9
|
-
if (isWindows) {
|
|
10
|
-
path = process.env.TEMP ||
|
|
11
|
-
process.env.TMP ||
|
|
12
|
-
(process.env.SystemRoot || process.env.windir) + '\\temp';
|
|
13
|
-
} else {
|
|
14
|
-
path = process.env.TMPDIR ||
|
|
15
|
-
process.env.TMP ||
|
|
16
|
-
process.env.TEMP ||
|
|
17
|
-
'/tmp';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (trailingSlashRe.test(path)) {
|
|
21
|
-
path = path.slice(0, -1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return path;
|
|
25
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# os-tmpdir [](https://travis-ci.org/sindresorhus/os-tmpdir)
|
|
2
|
-
|
|
3
|
-
> Node.js [`os.tmpdir()`](https://nodejs.org/api/os.html#os_os_tmpdir) [ponyfill](https://ponyfill.com)
|
|
4
|
-
|
|
5
|
-
Use this instead of `require('os').tmpdir()` to get a consistent behavior on different Node.js versions (even 0.8).
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## Install
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
$ npm install --save os-tmpdir
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
const osTmpdir = require('os-tmpdir');
|
|
19
|
-
|
|
20
|
-
osTmpdir();
|
|
21
|
-
//=> '/var/folders/m3/5574nnhn0yj488ccryqr7tc80000gn/T'
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## API
|
|
26
|
-
|
|
27
|
-
See the [`os.tmpdir()` docs](https://nodejs.org/api/os.html#os_os_tmpdir).
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## License
|
|
31
|
-
|
|
32
|
-
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014 KARASZI István
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
# Tmp
|
|
2
|
-
|
|
3
|
-
A simple temporary file and directory creator for [node.js.][1]
|
|
4
|
-
|
|
5
|
-
[](https://travis-ci.org/raszi/node-tmp)
|
|
6
|
-
[](https://david-dm.org/raszi/node-tmp)
|
|
7
|
-
[](https://badge.fury.io/js/tmp)
|
|
8
|
-
[](https://raszi.github.io/node-tmp/)
|
|
9
|
-
[](https://snyk.io/test/npm/tmp)
|
|
10
|
-
|
|
11
|
-
## About
|
|
12
|
-
|
|
13
|
-
This is a [widely used library][2] to create temporary files and directories
|
|
14
|
-
in a [node.js][1] environment.
|
|
15
|
-
|
|
16
|
-
Tmp offers both an asynchronous and a synchronous API. For all API calls, all
|
|
17
|
-
the parameters are optional. There also exists a promisified version of the
|
|
18
|
-
API, see (5) under references below.
|
|
19
|
-
|
|
20
|
-
Tmp uses crypto for determining random file names, or, when using templates,
|
|
21
|
-
a six letter random identifier. And just in case that you do not have that much
|
|
22
|
-
entropy left on your system, Tmp will fall back to pseudo random numbers.
|
|
23
|
-
|
|
24
|
-
You can set whether you want to remove the temporary file on process exit or
|
|
25
|
-
not, and the destination directory can also be set.
|
|
26
|
-
|
|
27
|
-
## How to install
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm install tmp
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Usage
|
|
34
|
-
|
|
35
|
-
Please also check [API docs][4].
|
|
36
|
-
|
|
37
|
-
### Asynchronous file creation
|
|
38
|
-
|
|
39
|
-
Simple temporary file creation, the file will be closed and unlinked on process exit.
|
|
40
|
-
|
|
41
|
-
```javascript
|
|
42
|
-
var tmp = require('tmp');
|
|
43
|
-
|
|
44
|
-
tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
|
|
45
|
-
if (err) throw err;
|
|
46
|
-
|
|
47
|
-
console.log('File: ', path);
|
|
48
|
-
console.log('Filedescriptor: ', fd);
|
|
49
|
-
|
|
50
|
-
// If we don't need the file anymore we could manually call the cleanupCallback
|
|
51
|
-
// But that is not necessary if we didn't pass the keep option because the library
|
|
52
|
-
// will clean after itself.
|
|
53
|
-
cleanupCallback();
|
|
54
|
-
});
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Synchronous file creation
|
|
58
|
-
|
|
59
|
-
A synchronous version of the above.
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
var tmp = require('tmp');
|
|
63
|
-
|
|
64
|
-
var tmpobj = tmp.fileSync();
|
|
65
|
-
console.log('File: ', tmpobj.name);
|
|
66
|
-
console.log('Filedescriptor: ', tmpobj.fd);
|
|
67
|
-
|
|
68
|
-
// If we don't need the file anymore we could manually call the removeCallback
|
|
69
|
-
// But that is not necessary if we didn't pass the keep option because the library
|
|
70
|
-
// will clean after itself.
|
|
71
|
-
tmpobj.removeCallback();
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Note that this might throw an exception if either the maximum limit of retries
|
|
75
|
-
for creating a temporary name fails, or, in case that you do not have the permission
|
|
76
|
-
to write to the directory where the temporary file should be created in.
|
|
77
|
-
|
|
78
|
-
### Asynchronous directory creation
|
|
79
|
-
|
|
80
|
-
Simple temporary directory creation, it will be removed on process exit.
|
|
81
|
-
|
|
82
|
-
If the directory still contains items on process exit, then it won't be removed.
|
|
83
|
-
|
|
84
|
-
```javascript
|
|
85
|
-
var tmp = require('tmp');
|
|
86
|
-
|
|
87
|
-
tmp.dir(function _tempDirCreated(err, path, cleanupCallback) {
|
|
88
|
-
if (err) throw err;
|
|
89
|
-
|
|
90
|
-
console.log('Dir: ', path);
|
|
91
|
-
|
|
92
|
-
// Manual cleanup
|
|
93
|
-
cleanupCallback();
|
|
94
|
-
});
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
If you want to cleanup the directory even when there are entries in it, then
|
|
98
|
-
you can pass the `unsafeCleanup` option when creating it.
|
|
99
|
-
|
|
100
|
-
### Synchronous directory creation
|
|
101
|
-
|
|
102
|
-
A synchronous version of the above.
|
|
103
|
-
|
|
104
|
-
```javascript
|
|
105
|
-
var tmp = require('tmp');
|
|
106
|
-
|
|
107
|
-
var tmpobj = tmp.dirSync();
|
|
108
|
-
console.log('Dir: ', tmpobj.name);
|
|
109
|
-
// Manual cleanup
|
|
110
|
-
tmpobj.removeCallback();
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Note that this might throw an exception if either the maximum limit of retries
|
|
114
|
-
for creating a temporary name fails, or, in case that you do not have the permission
|
|
115
|
-
to write to the directory where the temporary directory should be created in.
|
|
116
|
-
|
|
117
|
-
### Asynchronous filename generation
|
|
118
|
-
|
|
119
|
-
It is possible with this library to generate a unique filename in the specified
|
|
120
|
-
directory.
|
|
121
|
-
|
|
122
|
-
```javascript
|
|
123
|
-
var tmp = require('tmp');
|
|
124
|
-
|
|
125
|
-
tmp.tmpName(function _tempNameGenerated(err, path) {
|
|
126
|
-
if (err) throw err;
|
|
127
|
-
|
|
128
|
-
console.log('Created temporary filename: ', path);
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Synchronous filename generation
|
|
133
|
-
|
|
134
|
-
A synchronous version of the above.
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
var tmp = require('tmp');
|
|
138
|
-
|
|
139
|
-
var name = tmp.tmpNameSync();
|
|
140
|
-
console.log('Created temporary filename: ', name);
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Advanced usage
|
|
144
|
-
|
|
145
|
-
### Asynchronous file creation
|
|
146
|
-
|
|
147
|
-
Creates a file with mode `0644`, prefix will be `prefix-` and postfix will be `.txt`.
|
|
148
|
-
|
|
149
|
-
```javascript
|
|
150
|
-
var tmp = require('tmp');
|
|
151
|
-
|
|
152
|
-
tmp.file({ mode: 0644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileCreated(err, path, fd) {
|
|
153
|
-
if (err) throw err;
|
|
154
|
-
|
|
155
|
-
console.log('File: ', path);
|
|
156
|
-
console.log('Filedescriptor: ', fd);
|
|
157
|
-
});
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### Synchronous file creation
|
|
161
|
-
|
|
162
|
-
A synchronous version of the above.
|
|
163
|
-
|
|
164
|
-
```javascript
|
|
165
|
-
var tmp = require('tmp');
|
|
166
|
-
|
|
167
|
-
var tmpobj = tmp.fileSync({ mode: 0644, prefix: 'prefix-', postfix: '.txt' });
|
|
168
|
-
console.log('File: ', tmpobj.name);
|
|
169
|
-
console.log('Filedescriptor: ', tmpobj.fd);
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Controlling the Descriptor
|
|
173
|
-
|
|
174
|
-
As a side effect of creating a unique file `tmp` gets a file descriptor that is
|
|
175
|
-
returned to the user as the `fd` parameter. The descriptor may be used by the
|
|
176
|
-
application and is closed when the `removeCallback` is invoked.
|
|
177
|
-
|
|
178
|
-
In some use cases the application does not need the descriptor, needs to close it
|
|
179
|
-
without removing the file, or needs to remove the file without closing the
|
|
180
|
-
descriptor. Two options control how the descriptor is managed:
|
|
181
|
-
|
|
182
|
-
* `discardDescriptor` - if `true` causes `tmp` to close the descriptor after the file
|
|
183
|
-
is created. In this case the `fd` parameter is undefined.
|
|
184
|
-
* `detachDescriptor` - if `true` causes `tmp` to return the descriptor in the `fd`
|
|
185
|
-
parameter, but it is the application's responsibility to close it when it is no
|
|
186
|
-
longer needed.
|
|
187
|
-
|
|
188
|
-
```javascript
|
|
189
|
-
var tmp = require('tmp');
|
|
190
|
-
|
|
191
|
-
tmp.file({ discardDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
|
|
192
|
-
if (err) throw err;
|
|
193
|
-
// fd will be undefined, allowing application to use fs.createReadStream(path)
|
|
194
|
-
// without holding an unused descriptor open.
|
|
195
|
-
});
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
```javascript
|
|
199
|
-
var tmp = require('tmp');
|
|
200
|
-
|
|
201
|
-
tmp.file({ detachDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
|
|
202
|
-
if (err) throw err;
|
|
203
|
-
|
|
204
|
-
cleanupCallback();
|
|
205
|
-
// Application can store data through fd here; the space used will automatically
|
|
206
|
-
// be reclaimed by the operating system when the descriptor is closed or program
|
|
207
|
-
// terminates.
|
|
208
|
-
});
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### Asynchronous directory creation
|
|
212
|
-
|
|
213
|
-
Creates a directory with mode `0755`, prefix will be `myTmpDir_`.
|
|
214
|
-
|
|
215
|
-
```javascript
|
|
216
|
-
var tmp = require('tmp');
|
|
217
|
-
|
|
218
|
-
tmp.dir({ mode: 0750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path) {
|
|
219
|
-
if (err) throw err;
|
|
220
|
-
|
|
221
|
-
console.log('Dir: ', path);
|
|
222
|
-
});
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Synchronous directory creation
|
|
226
|
-
|
|
227
|
-
Again, a synchronous version of the above.
|
|
228
|
-
|
|
229
|
-
```javascript
|
|
230
|
-
var tmp = require('tmp');
|
|
231
|
-
|
|
232
|
-
var tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
|
|
233
|
-
console.log('Dir: ', tmpobj.name);
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### mkstemp like, asynchronously
|
|
237
|
-
|
|
238
|
-
Creates a new temporary directory with mode `0700` and filename like `/tmp/tmp-nk2J1u`.
|
|
239
|
-
|
|
240
|
-
```javascript
|
|
241
|
-
var tmp = require('tmp');
|
|
242
|
-
|
|
243
|
-
tmp.dir({ template: '/tmp/tmp-XXXXXX' }, function _tempDirCreated(err, path) {
|
|
244
|
-
if (err) throw err;
|
|
245
|
-
|
|
246
|
-
console.log('Dir: ', path);
|
|
247
|
-
});
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
### mkstemp like, synchronously
|
|
251
|
-
|
|
252
|
-
This will behave similarly to the asynchronous version.
|
|
253
|
-
|
|
254
|
-
```javascript
|
|
255
|
-
var tmp = require('tmp');
|
|
256
|
-
|
|
257
|
-
var tmpobj = tmp.dirSync({ template: '/tmp/tmp-XXXXXX' });
|
|
258
|
-
console.log('Dir: ', tmpobj.name);
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
### Asynchronous filename generation
|
|
262
|
-
|
|
263
|
-
The `tmpName()` function accepts the `prefix`, `postfix`, `dir`, etc. parameters also:
|
|
264
|
-
|
|
265
|
-
```javascript
|
|
266
|
-
var tmp = require('tmp');
|
|
267
|
-
|
|
268
|
-
tmp.tmpName({ template: '/tmp/tmp-XXXXXX' }, function _tempNameGenerated(err, path) {
|
|
269
|
-
if (err) throw err;
|
|
270
|
-
|
|
271
|
-
console.log('Created temporary filename: ', path);
|
|
272
|
-
});
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### Synchronous filename generation
|
|
276
|
-
|
|
277
|
-
The `tmpNameSync()` function works similarly to `tmpName()`.
|
|
278
|
-
|
|
279
|
-
```javascript
|
|
280
|
-
var tmp = require('tmp');
|
|
281
|
-
var tmpname = tmp.tmpNameSync({ template: '/tmp/tmp-XXXXXX' });
|
|
282
|
-
console.log('Created temporary filename: ', tmpname);
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
## Graceful cleanup
|
|
286
|
-
|
|
287
|
-
One may want to cleanup the temporary files even when an uncaught exception
|
|
288
|
-
occurs. To enforce this, you can call the `setGracefulCleanup()` method:
|
|
289
|
-
|
|
290
|
-
```javascript
|
|
291
|
-
var tmp = require('tmp');
|
|
292
|
-
|
|
293
|
-
tmp.setGracefulCleanup();
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Options
|
|
297
|
-
|
|
298
|
-
All options are optional :)
|
|
299
|
-
|
|
300
|
-
* `mode`: the file mode to create with, it fallbacks to `0600` on file creation and `0700` on directory creation
|
|
301
|
-
* `prefix`: the optional prefix, fallbacks to `tmp-` if not provided
|
|
302
|
-
* `postfix`: the optional postfix, fallbacks to `.tmp` on file creation
|
|
303
|
-
* `template`: [`mkstemp`][3] like filename template, no default
|
|
304
|
-
* `dir`: the optional temporary directory, fallbacks to system default (guesses from environment)
|
|
305
|
-
* `tries`: how many times should the function try to get a unique filename before giving up, default `3`
|
|
306
|
-
* `keep`: signals that the temporary file or directory should not be deleted on exit, default is `false`, means delete
|
|
307
|
-
* Please keep in mind that it is recommended in this case to call the provided `cleanupCallback` function manually.
|
|
308
|
-
* `unsafeCleanup`: recursively removes the created temporary directory, even when it's not empty. default is `false`
|
|
309
|
-
|
|
310
|
-
[1]: http://nodejs.org/
|
|
311
|
-
[2]: https://www.npmjs.com/browse/depended/tmp
|
|
312
|
-
[3]: http://www.kernel.org/doc/man-pages/online/pages/man3/mkstemp.3.html
|
|
313
|
-
[4]: https://raszi.github.io/node-tmp/
|
|
314
|
-
[5]: https://github.com/benjamingr/tmp-promise
|