MCPcopy Create free account
hub / github.com/nodejs/node / normalizeFlags

Function normalizeFlags

lib/internal/vfs/providers/memory.js:64–83  ·  view source on GitHub ↗

* Converts numeric flags to a string representation. * If already a string, returns as-is. * @param {string|number} flags The flags to normalize * @returns {string} Normalized string flags

(flags)

Source from the content-addressed store, hash-verified

62 * @returns {string} Normalized string flags
63 */
64function normalizeFlags(flags) {
65 if (typeof flags === 'string') return flags;
66 if (typeof flags !== 'number') return 'r';
67
68 const rdwr = (flags & O_RDWR) !== 0;
69 const append = (flags & O_APPEND) !== 0;
70 const excl = (flags & O_EXCL) !== 0;
71 const write = (flags & O_WRONLY) !== 0 ||
72 (flags & O_CREAT) !== 0 ||
73 (flags & O_TRUNC) !== 0;
74
75 if (append) {
76 return 'a' + (excl ? 'x' : '') + (rdwr ? '+' : '');
77 }
78 if (write) {
79 return 'w' + (excl ? 'x' : '') + (rdwr ? '+' : '');
80 }
81 if (rdwr) return 'r+';
82 return 'r';
83}
84
85/**
86 * Converts a time argument (Date, number, or string) to milliseconds.

Callers 1

openSyncMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected