Home > Web Front-end > JS Tutorial > About the difference between fs.stat and fs.fstat in node.js

About the difference between fs.stat and fs.fstat in node.js

不言
Release: 2018-06-30 11:35:35
Original
1861 people have browsed it

fs.stat and fs.fstat are both used to obtain status information of files. The following article mainly introduces relevant information about the difference between fs.stat and fs.fstat in node.js. The following is introduced in the article It is very detailed and has certain reference and learning value for everyone. Friends who need it can take a look below.

Preface

fs.stat and fs.fstat have the same method functions, they both obtain the status information of the file. This article mainly This article introduces the relevant content about the difference between fs.stat and fs.fstat in node.js. It is shared for everyone’s reference and study. Let’s take a look at the detailed introduction:

##fs.stat Usage:

fs.stat('./aa.js', function(err, stats) { 
 if (err) { 
 throw err; 
 } 
 console.log(stats); 
});
Copy after login

##fs.fstat Usage:

fs.open('./aa.js', 'a', function(err, fd) { 
 if (err) { 
 throw err; 
 } 
 fs.fstat(fd, function(err, stats) { 
 if (err) { 
  throw err; 
 } 
 console.log(stats); 
 }); 
})
Copy after login

The first parameter fs.stat receives is a file path string


fs.fstat receives a File descriptor;

The kernel uses file descriptors to access files. File descriptors are nonnegative integers. When opening an existing file or creating a new file, the kernel returns a file descriptor. To read and write files, you also need to use a file descriptor to specify the file to be read and written.

Other Fs methods are similar to this description;


The above is the content of this article All content, I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

NodeJs form-data format transfer file method


The principle of Node.js event-driven mechanism


The above is the detailed content of About the difference between fs.stat and fs.fstat in node.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template