| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent af49e58 commit c885ea7
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -719,6 +719,15 @@ The internal `path._makeLong()` was not intended for public use. However, | |||
| 719 | 719 | userland modules have found it useful. The internal API has been deprecated | |
| 720 | 720 | and replaced with an identical, public `path.toNamespacedPath()` method. | |
| 721 | 721 | ||
| 722 | + <a id="DEP0081"></a> | ||
| 723 | + ### DEP0081: fs.truncate() using a file descriptor | ||
| 724 | + | ||
| 725 | + Type: Runtime | ||
| 726 | + | ||
| 727 | + `fs.truncate()` `fs.truncateSync()` usage with a file descriptor has been | ||
| 728 | + deprecated. Please use `fs.ftruncate()` or `fs.ftruncateSync()` to work with | ||
| 729 | + file descriptors. | ||
| 730 | + | ||
| 722 | 731 | ||
| 723 | 732 | [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size | |
| 724 | 733 | [`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2266,6 +2266,9 @@ Asynchronous truncate(2). No arguments other than a possible exception are | |||
| 2266 | 2266 | given to the completion callback. A file descriptor can also be passed as the | |
| 2267 | 2267 | first argument. In this case, `fs.ftruncate()` is called. | |
| 2268 | 2268 | ||
| 2269 | + *Note*: Passing a file descriptor is deprecated and may result in an error | ||
| 2270 | + being thrown in the future. | ||
| 2271 | + | ||
| 2269 | 2272 | ## fs.truncateSync(path[, len]) | |
| 2270 | 2273 | <!-- YAML | |
| 2271 | 2274 | added: v0.8.6 | |
@@ -2277,6 +2280,9 @@ added: v0.8.6 | |||
| 2277 | 2280 | Synchronous truncate(2). Returns `undefined`. A file descriptor can also be | |
| 2278 | 2281 | passed as the first argument. In this case, `fs.ftruncateSync()` is called. | |
| 2279 | 2282 | ||
| 2283 | + *Note*: Passing a file descriptor is deprecated and may result in an error | ||
| 2284 | + being thrown in the future. | ||
| 2285 | + | ||
| 2280 | 2286 | ## fs.unlink(path, callback) | |
| 2281 | 2287 | <!-- YAML | |
| 2282 | 2288 | added: v0.0.2 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,18 @@ const isWindows = process.platform === 'win32'; | |||
| 63 | 63 | const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG); | |
| 64 | 64 | const errnoException = util._errnoException; | |
| 65 | 65 | ||
| 66 | + let truncateWarn = true; | ||
| 67 | + | ||
| 68 | + function showTruncateDeprecation() { | ||
| 69 | + if (truncateWarn) { | ||
| 70 | + process.emitWarning( | ||
| 71 | + 'Using fs.truncate with a file descriptor is deprecated. Please use ' + | ||
| 72 | + 'fs.ftruncate with a file descriptor instead.', | ||
| 73 | + 'DeprecationWarning', 'DEP0081'); | ||
| 74 | + truncateWarn = false; | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 66 | 78 | function getOptions(options, defaultOptions) { | |
| 67 | 79 | if (options === null || options === undefined || | |
| 68 | 80 | typeof options === 'function') { | |
@@ -783,6 +795,7 @@ fs.renameSync = function(oldPath, newPath) { | |||
| 783 | 795 | ||
| 784 | 796 | fs.truncate = function(path, len, callback) { | |
| 785 | 797 | if (typeof path === 'number') { | |
| 798 | + showTruncateDeprecation(); | ||
| 786 | 799 | return fs.ftruncate(path, len, callback); | |
| 787 | 800 | } | |
| 788 | 801 | if (typeof len === 'function') { | |
@@ -808,6 +821,7 @@ fs.truncate = function(path, len, callback) { | |||
| 808 | 821 | fs.truncateSync = function(path, len) { | |
| 809 | 822 | if (typeof path === 'number') { | |
| 810 | 823 | // legacy | |
| 824 | + showTruncateDeprecation(); | ||
| 811 | 825 | return fs.ftruncateSync(path, len); | |
| 812 | 826 | } | |
| 813 | 827 | if (len === undefined) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,12 @@ const filename = path.resolve(tmp, 'truncate-file.txt'); | |||
| 9 | 9 | ||
| 10 | 10 | fs.writeFileSync(filename, 'hello world', 'utf8'); | |
| 11 | 11 | const fd = fs.openSync(filename, 'r+'); | |
| 12 | + | ||
| 13 | + const msg = 'Using fs.truncate with a file descriptor is deprecated.' + | ||
| 14 | + ' Please use fs.ftruncate with a file descriptor instead.'; | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + common.expectWarning('DeprecationWarning', msg); | ||
| 12 | 18 | fs.truncate(fd, 5, common.mustCall(function(err) { | |
| 13 | 19 | assert.ok(!err); | |
| 14 | 20 | assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,9 @@ common.refreshTmpDir(); | |||
| 32 | 32 | ||
| 33 | 33 | let stat; | |
| 34 | 34 | ||
| 35 | + const msg = 'Using fs.truncate with a file descriptor is deprecated.' + | ||
| 36 | + ' Please use fs.ftruncate with a file descriptor instead.'; | ||
| 37 | + | ||
| 35 | 38 | // truncateSync | |
| 36 | 39 | fs.writeFileSync(filename, data); | |
| 37 | 40 | stat = fs.statSync(filename); | |
@@ -60,6 +63,10 @@ fs.ftruncateSync(fd); | |||
| 60 | 63 | stat = fs.statSync(filename); | |
| 61 | 64 | assert.strictEqual(stat.size, 0); | |
| 62 | 65 | ||
| 66 | + // truncateSync | ||
| 67 | + common.expectWarning('DeprecationWarning', msg); | ||
| 68 | + fs.truncateSync(fd); | ||
| 69 | + | ||
| 63 | 70 | fs.closeSync(fd); | |
| 64 | 71 | ||
| 65 | 72 | // async tests | |
| Back | FazBrowse Home | New Git URL |
0 commit comments