Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Latest commit

 

History

History
90 lines (57 loc) · 3.82 KB

internal-api.md

File metadata and controls

90 lines (57 loc) · 3.82 KB

An hidden documentation for exported function that are for advanced use case.

Table of contents

File permissions and Windows

File permissions, read/write/execute, is a concept from Linux also available on MacOS. For this reason you cannot use the following functions on Windows:

This limitation is inherited from Node.js. The following paragraph is quoted from Node.js documentation

Caveats: on Windows only the write permission can be changed, and the distinction among the permissions of group, owner or others is not implemented.

In other words it's unusable on Windows. In the end working with file permission is not common, you certainly don't need them.

— See File modes documentation on Node.js

grantPermissionsOnFileSystemNode

grantPermissionsOnFileSystemNode is an async function granting permission on a given file system node. It returns an async function restoring the previous permissions.

Do not use on Windows because of file permissions caveat

import { grantPermissionsOnFileSystemNode } from "@jsenv/util"

const restorePermissions = await grantPermissionsOnFileSystemNode("file:///file.js", {
  execute: true,
})
await restorePermissions()

— source code at src/grantPermissionsOnFileSystemNode.js.

readFileSystemNodePermissions

readFileSystemNodePermissions is an async function returning an object representing the permissions of a given filesystem node.

Do not use on Windows because of file permissions caveat

import { readFileSystemNodePermissions } from "@jsenv/util"

const permissions = await readFileSystemNodePermissions("file:///directory/file.js")

— see also file modes documentation on Node.js
— source code at src/readFileSystemNodePermissions.js.

testFileSystemNodePermissions

testFileSystemNodePermissions is an async function returning a boolean indicating if current user has read/write/execute permission on the filesystem node.

Do not use on Windows because of file permissions caveat

import { testFileSystemNodePermissions } from "@jsenv/util"

const allowed = await testFileSystemNodePermissions("file:///file.js", { execute: true })

— source code at src/testFileSystemNodePermissions.js.

writeFileSystemNodePermissions

writeFileSystemNodePermissions is an async function setting the permissions of a filesystem node.

Do not use on Windows because of file permissions caveat

import { writeFileSystemNodePermissions } from "@jsenv/util"

await writeFileSystemNodePermissions("file:///directory/file.js", {
  owner: { read: true, write: true, execute: true },
  group: { read: true, write: true, execute: false },
  others: { read: true, write: false, execute: false },
})

— see also file modes documentation on Node.js
— source code at src/writeFileSystemNodePermissions.js.