UNPKG

1.19 kBJavaScriptView Raw
1'use strict';
2
3const util = require('util');
4
5const Item = require('./item');
6
7const constants = require('constants');
8
9/**
10 * A directory.
11 * @constructor
12 */
13function SymbolicLink() {
14 Item.call(this);
15
16 /**
17 * Relative path to source.
18 * @type {string}
19 */
20 this._path = undefined;
21}
22util.inherits(SymbolicLink, Item);
23
24/**
25 * Set the path to the source.
26 * @param {string} pathname Path to source.
27 */
28SymbolicLink.prototype.setPath = function(pathname) {
29 this._path = pathname;
30};
31
32/**
33 * Get the path to the source.
34 * @return {string} Path to source.
35 */
36SymbolicLink.prototype.getPath = function() {
37 return this._path;
38};
39
40/**
41 * Get symbolic link stats.
42 * @return {Object} Stats properties.
43 */
44SymbolicLink.prototype.getStats = function(bigint) {
45 const size = this._path.length;
46 const stats = Item.prototype.getStats.call(this, bigint);
47 const convert = bigint ? v => BigInt(v) : v => v;
48
49 stats[1] = convert(this.getMode() | constants.S_IFLNK); // mode
50 stats[8] = convert(size); // size
51 stats[9] = convert(Math.ceil(size / 512)); // blocks
52
53 return stats;
54};
55
56/**
57 * Export the constructor.
58 * @type {function()}
59 */
60exports = module.exports = SymbolicLink;