@vscode-utility/fs-browserify
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,2 +0,3 @@ | ||
import { FileStat, FileType, Uri } from 'vscode'; | ||
import { FileStat, FileSystemWatcher, FileType, Uri } from 'vscode'; | ||
import { FileAccess } from '.'; | ||
/** | ||
@@ -91,3 +92,3 @@ * The file system interface allows extensions to manipulate both local and remote files, | ||
* @param source The existing file. | ||
* @param destination The destination location. | ||
* @param target The destination location. | ||
* @param options Defines if existing files should be overwritten. | ||
@@ -113,8 +114,29 @@ */ | ||
/** | ||
* Truncates the file to change the size of the file i.e either increase or decrease the file size | ||
* Truncates the file to change the size of the file i.e either increase or decrease the file size. | ||
* | ||
* @param filePath This property contains the path of the target file, which can be either a string, buffer or URL. | ||
* @param length This property sets the file length for truncation, with an optional integer input. If not specified, the default value is 0. | ||
* @param path The path of the target file. | ||
* @param length The file length for truncation, with an optional integer input. If not specified, the default value is 0. | ||
*/ | ||
truncateAsync: (path: string | Uri, length: number) => Promise<void>; | ||
truncateAsync: (path: string | Uri, length?: number) => Promise<void>; | ||
/** | ||
* Watch the specified file for changes continuously. | ||
* | ||
* @param pattern A pattern expressed in glob syntax that is used to match the absolute paths of files that have been created, changed, or deleted. | ||
* @param ignoreCreateEvents Ignore when files have been created. | ||
* @param ignoreChangeEvents Ignore when files have been changed. | ||
* @param ignoreDeleteEvents Ignore when files have been deleted. | ||
* @return A new file system watcher instance. | ||
*/ | ||
watch: (pattern: string, options?: { | ||
ignoreCreateEvents?: boolean; | ||
ignoreChangeEvents?: boolean; | ||
ignoreDeleteEvents?: boolean; | ||
}) => FileSystemWatcher; | ||
/** | ||
* Check the permissions of a given file | ||
* | ||
* @param path The path of the file. | ||
* @return `FileAccess.Write` if the file system supports writing, `FileAccess.Read` if it is read-only, and `FileAccess.None` if the editor is unaware of the file system. | ||
*/ | ||
access: (path: string | Uri) => FileAccess; | ||
} |
@@ -0,1 +1,6 @@ | ||
export declare enum FileAccess { | ||
None = 0, | ||
Read = 1, | ||
Write = 2 | ||
} | ||
export * from './fs'; |
@@ -1,1 +0,1 @@ | ||
"use strict";var g=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var w=(o,t)=>{for(var e in t)g(o,e,{get:t[e],enumerable:!0})},h=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of d(t))!u.call(o,i)&&i!==e&&g(o,i,{get:()=>t[i],enumerable:!(r=l(t,i))||r.enumerable});return o};var A=o=>h(g({},"__esModule",{value:!0}),o);var f={};w(f,{fs:()=>m});module.exports=A(f);var c=require("vscode"),{fs:n}=c.workspace,y=class{getUri=t=>t instanceof c.Uri?t:c.Uri.file(t);getContentBytes=t=>t instanceof Uint8Array?t:new TextEncoder().encode(t);statAsync=async t=>{let e=this.getUri(t);return await n.stat(e)};readDirectoryAsync=async t=>{let e=this.getUri(t);return await n.readDirectory(e)};createDirectoryAsync=async t=>{let e=this.getUri(t);await n.createDirectory(e)};readFileAsync=async(t,e)=>{let r=this.getUri(t),i=await n.readFile(r),{encoding:s="utf-8",fatal:a,ignoreBOM:U}=e||{};return new TextDecoder(s,{fatal:a,ignoreBOM:U}).decode(i)};appendFileAsync=async(t,e)=>{let r=this.getUri(t),i=new Uint8Array(0);await this.existAsync(r)&&(i=await n.readFile(r));let s=this.getContentBytes(e),a=new Uint8Array(i.length+s.length);a.set(i,0),a.set(s,i.length),await n.writeFile(r,a)};writeFileAsync=async(t,e)=>{let r=this.getUri(t),i=this.getContentBytes(e);await n.writeFile(r,i)};deleteAsync=async(t,e)=>{let r=this.getUri(t);await n.delete(r,e)};renameAsync=async(t,e,r)=>{let i=this.getUri(t),s=this.getUri(e);await n.rename(i,s,r)};copyAsync=async(t,e,r)=>{let i=this.getUri(t),s=this.getUri(e);await n.copy(i,s,r)};isWritableFileSystem=t=>n.isWritableFileSystem(t);existAsync=async t=>{try{let e=this.getUri(t);return await n.stat(e),!0}catch{return!1}};truncateAsync=async(t,e)=>{try{let r=this.getUri(t),s=(await this.readFileAsync(r)).slice(0,e);await this.writeFileAsync(r,s)}catch(r){console.error(r)}}};var m=new y;0&&(module.exports={fs}); | ||
"use strict";var y=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var h=(o,e)=>{for(var t in e)y(o,t,{get:e[t],enumerable:!0})},m=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of d(e))!u.call(o,i)&&i!==t&&y(o,i,{get:()=>e[i],enumerable:!(r=U(e,i))||r.enumerable});return o};var w=o=>m(y({},"__esModule",{value:!0}),o);var v={};h(v,{fs:()=>A});module.exports=w(v);var c=require("vscode");var{fs:s,createFileSystemWatcher:f}=c.workspace,g=class{getUri=e=>e instanceof c.Uri?e:c.Uri.file(e);getContentBytes=e=>e instanceof Uint8Array?e:new TextEncoder().encode(e);statAsync=async e=>{let t=this.getUri(e);return await s.stat(t)};readDirectoryAsync=async e=>{let t=this.getUri(e);return await s.readDirectory(t)};createDirectoryAsync=async e=>{let t=this.getUri(e);await s.createDirectory(t)};readFileAsync=async(e,t)=>{let r=this.getUri(e),i=await s.readFile(r),{encoding:n="utf-8",fatal:a,ignoreBOM:l}=t||{};return new TextDecoder(n,{fatal:a,ignoreBOM:l}).decode(i)};appendFileAsync=async(e,t)=>{let r=this.getUri(e),i=new Uint8Array(0);await this.existAsync(r)&&(i=await s.readFile(r));let n=this.getContentBytes(t),a=new Uint8Array(i.length+n.length);a.set(i,0),a.set(n,i.length),await s.writeFile(r,a)};writeFileAsync=async(e,t)=>{let r=this.getUri(e),i=this.getContentBytes(t);await s.writeFile(r,i)};deleteAsync=async(e,t)=>{let r=this.getUri(e);await s.delete(r,t)};renameAsync=async(e,t,r)=>{let i=this.getUri(e),n=this.getUri(t);await s.rename(i,n,r)};copyAsync=async(e,t,r)=>{let i=this.getUri(e),n=this.getUri(t);await s.copy(i,n,r)};isWritableFileSystem=e=>s.isWritableFileSystem(e);existAsync=async e=>{try{let t=this.getUri(e);return await s.stat(t),!0}catch{return!1}};truncateAsync=async(e,t=0)=>{try{let r=this.getUri(e),n=(await this.readFileAsync(r)).slice(0,t);await this.writeFileAsync(r,n)}catch(r){console.error(r)}};watch=(e,t)=>{let{ignoreCreateEvents:r=!1,ignoreChangeEvents:i=!1,ignoreDeleteEvents:n=!1}=t||{};return f(e,r,i,n)};access=e=>{let t=this.getUri(e),r=this.isWritableFileSystem(t.scheme);return r===void 0?0:r?2:1}};var A=new g;0&&(module.exports={fs}); |
@@ -5,3 +5,3 @@ { | ||
"description": "The `fs` module compatible for VS Code Web Extensions", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "./dist/index.js", | ||
@@ -8,0 +8,0 @@ "private": false, |
@@ -13,6 +13,8 @@ [![CI](https://github.com/nguyenngoclongdev/vscode-fs-browserify/actions/workflows/ci.yml/badge.svg)](https://github.com/nguyenngoclongdev/vscode-fs-browserify/actions/workflows/ci.yml) | ||
When developing vscode extensions, it is essential to ensure compatibility between the desktop and web versions of vscode (https://vscode.dev or https://github.dev). | ||
When developing vscode extensions, it is essential to ensure compatibility between the desktop and web versions of vscode (https://vscode.dev or https://github.dev). | ||
Using `@vscode-utility/fs-browserify`, you can access and manipulate files stored locally or remotely, making it easier to develop vscode extensions that work seamlessly on both the desktop and web versions of vscode. | ||
This library utilizes a portion of the [File System](https://code.visualstudio.com/api/references/vscode-api#FileSystem) provided by the [VS Code API](https://code.visualstudio.com/api/references/vscode-api). | ||
If you find this package useful for your projects, please consider supporting me by [Buy Me a Coffee](https://ko-fi.com/D1D2LBPX9). It's a great way to help me maintain and improve this package in the future. Your support is truly appreciated! | ||
@@ -27,2 +29,3 @@ | ||
**npm** | ||
```sh | ||
@@ -33,2 +36,3 @@ npm install @vscode-utility/fs-browserify | ||
**yarn** | ||
```sh | ||
@@ -39,2 +43,3 @@ yarn add @vscode-utility/fs-browserify | ||
**pnpm** | ||
```sh | ||
@@ -49,7 +54,37 @@ pnpm add @vscode-utility/fs-browserify | ||
const fileStat = await fs.statAsync(path); | ||
console.log(fileStat); | ||
// Retrieve file metadata | ||
await fs.statAsync(path); | ||
const fileContent = await fs.readFileAsync(path); | ||
console.log(fileContent); | ||
// Retrieve all directory entries | ||
await fs.readDirectoryAsync(path); | ||
// Create a new directory | ||
await fs.createDirectoryAsync(path); | ||
// Read the full content of a file | ||
await fs.readFileAsync(path, options); | ||
// Append the provided data to a file | ||
await fs.appendFileAsync(path, content); | ||
// Write data to a file and replace its full contents | ||
await fs.writeFileAsync(path, content); | ||
// Delete a file | ||
await fs.deleteAsync(path, options); | ||
// Rename a file or folder | ||
await fs.renameAsync(source, target, options); | ||
// Copy files or folders | ||
await fs.copyAsync(source, target, options); | ||
// Check if a given path exists or not in the file system | ||
await fs.existAsync(source); | ||
// Truncates the file to change the size of the file i.e either increase or decrease the file size | ||
await fs.existAsync(path, length); | ||
// Check the permissions of a given file | ||
fs.access(path); | ||
``` | ||
@@ -59,16 +94,31 @@ | ||
| @vscode-utility/fs-browserify | fs (nodejs) | | ||
| ----------------------------- | --------------- | | ||
| fs.statAsync() | fs.stat() | | ||
| fs.readDirectoryAsync() | fs.readDir() | | ||
| fs.createDirectoryAsync() | fs.mkdir() | | ||
| fs.readFileAsync() | fs.readFile() | | ||
| fs.appendFileAsync() | fs.appendFile() | | ||
| fs.writeFileAsync() | fs.writeFile() | | ||
| fs.deleteAsync() | fs.rmdir() | | ||
| fs.renameAsync() | fs.rename() | | ||
| fs.copyAsync() | fs.cp() | | ||
| fs.existAsync() | fs.exist() | | ||
| fs.truncateAsync() | fs.truncate() | | ||
| @vscode-utility/fs-browserify | fs (node) | fs (vscode api) | | ||
| ----------------------------- | ----------------- | ---------------------- | | ||
| fs.`statAsync`() | fs.`stat`() | fs.`stat`() | | ||
| fs.`readDirectoryAsync`() | fs.`readDir`() | fs.`readDirectory`() | | ||
| fs.`createDirectoryAsync`() | fs.`mkdir`() | fs.`createDirectory`() | | ||
| fs.`readFileAsync`() | fs.`readFile`() | fs.`readFile`() | | ||
| fs.`appendFileAsync`() | fs.`appendFile`() | <sub>undefined</sub> | | ||
| fs.`writeFileAsync`() | fs.`writeFile`() | fs.`writeFile`() | | ||
| fs.`deleteAsync`() | fs.`rmdir`() | fs.`delete`() | | ||
| fs.`renameAsync`() | fs.`rename`() | fs.`rename`() | | ||
| fs.`copyAsync`() | fs.`cp`() | fs.`copy`() | | ||
| fs.`existAsync`() | fs.`exist`() | <sub>undefined</sub> | | ||
| fs.`truncateAsync`() | fs.`truncate`() | <sub>undefined</sub> | | ||
| fs.`watch`() | fs.`watch`() | <sub>undefined</sub> | | ||
| fs.`access`() | fs.`access`() | <sub>undefined</sub> | | ||
- @vscode-utility/fs-browserify | ||
- Provides seamless compatibility for both the desktop and web versions of VS Code | ||
- Supports additional functions that are missing from the [File System API](https://code.visualstudio.com/api/references/vscode-api#FileSystem) | ||
- fs (node) | ||
- Only works with the desktop version of VS Code | ||
- fs (vscode api) | ||
- Missing some necessary functions for the File System | ||
## Feedback | ||
@@ -75,0 +125,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16746
161
126