From c885ea727da7ffd66deb5a775a0d1fb40f14a329 Mon Sep 17 00:00:00 2001 From: r1cebank Date: Fri, 6 Oct 2017 11:06:35 -0700 Subject: [PATCH] lib: deprecate fd usage for fs.truncate(Sync) PR-URL: https://github.com/nodejs/node/pull/15990 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Trevor Norris Reviewed-By: Colin Ihrig --- doc/api/deprecations.md | 9 +++++++++ doc/api/fs.md | 6 ++++++ lib/fs.js | 14 ++++++++++++++ test/parallel/test-fs-truncate-fd.js | 6 ++++++ test/parallel/test-fs-truncate.js | 7 +++++++ 5 files changed, 42 insertions(+) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 76165638839e38..2a21d645b6e46c 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -719,6 +719,15 @@ The internal `path._makeLong()` was not intended for public use. However, userland modules have found it useful. The internal API has been deprecated and replaced with an identical, public `path.toNamespacedPath()` method. + +### DEP0081: fs.truncate() using a file descriptor + +Type: Runtime + +`fs.truncate()` `fs.truncateSync()` usage with a file descriptor has been +deprecated. Please use `fs.ftruncate()` or `fs.ftruncateSync()` to work with +file descriptors. + [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size [`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array diff --git a/doc/api/fs.md b/doc/api/fs.md index 997a99a612402d..1d131ef5413e37 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2266,6 +2266,9 @@ Asynchronous truncate(2). No arguments other than a possible exception are given to the completion callback. A file descriptor can also be passed as the first argument. In this case, `fs.ftruncate()` is called. +*Note*: Passing a file descriptor is deprecated and may result in an error +being thrown in the future. + ## fs.truncateSync(path[, len])