Replace use of vscode.fs.writeFile with node equivalent (#4790)
* Replace use of vscode.fs.writeFile with node equivalent * format fix --------- Co-authored-by: Andrei Edell <andrei@nugbase.com>
This commit is contained in:
1 parent
0eaf350d87
commit
c724edd118
3 files changed
+24
-2
No files matched your search
@@ -4,6 +4,7 @@ import * as path from "path"
|
||||
import * as vscode from "vscode"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { ShowTextDocumentRequest, ShowTextDocumentOptions } from "@/shared/proto/host/window"
|
||||
import { writeFile } from "@utils/fs"
|
||||
|
||||
export async function downloadTask(dateTs: number, conversationHistory: Anthropic.MessageParam[]) {
|
||||
// File name
|
||||
@@ -39,7 +40,7 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
|
||||
if (saveUri) {
|
||||
try {
|
||||
// Write content to the selected location
|
||||
await vscode.workspace.fs.writeFile(saveUri, new TextEncoder().encode(markdownContent))
|
||||
await writeFile(saveUri.fsPath, markdownContent)
|
||||
await getHostBridgeProvider().windowClient.showTextDocument(
|
||||
ShowTextDocumentRequest.create({
|
||||
path: saveUri.fsPath,
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as vscode from "vscode"
|
||||
import { arePathsEqual } from "@utils/path"
|
||||
import { getHostBridgeProvider } from "@/hosts/host-providers"
|
||||
import { ShowTextDocumentRequest, ShowTextDocumentOptions } from "@/shared/proto/host/window"
|
||||
import { writeFile } from "@utils/fs"
|
||||
|
||||
export async function openImage(dataUri: string) {
|
||||
const matches = dataUri.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/)
|
||||
@@ -15,7 +16,7 @@ export async function openImage(dataUri: string) {
|
||||
const imageBuffer = Buffer.from(base64Data, "base64")
|
||||
const tempFilePath = path.join(os.tmpdir(), `temp_image_${Date.now()}.${format}`)
|
||||
try {
|
||||
await vscode.workspace.fs.writeFile(vscode.Uri.file(tempFilePath), new Uint8Array(imageBuffer))
|
||||
await writeFile(tempFilePath, new Uint8Array(imageBuffer))
|
||||
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(tempFilePath))
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(`Error opening image: ${error}`)
|
||||
|
||||
@@ -75,6 +75,26 @@ export async function getFileSizeInKB(filePath: string): Promise<number> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes content to a file
|
||||
* @param filePath - Absolute path to the file
|
||||
* @param content - Content to write (string or Uint8Array)
|
||||
* @param encoding - Text encoding (default: 'utf8')
|
||||
* @returns A promise that resolves when the file is written
|
||||
*/
|
||||
export async function writeFile(
|
||||
filePath: string,
|
||||
content: string | Uint8Array,
|
||||
encoding: BufferEncoding = "utf8",
|
||||
): Promise<void> {
|
||||
console.log("[DEBUG] writing file:", filePath, content.length, encoding)
|
||||
if (content instanceof Uint8Array) {
|
||||
await fs.writeFile(filePath, content)
|
||||
} else {
|
||||
await fs.writeFile(filePath, content, encoding)
|
||||
}
|
||||
}
|
||||
|
||||
// Common OS-generated files that would appear in an otherwise clean directory
|
||||
const OS_GENERATED_FILES = [
|
||||
".DS_Store", // macOS Finder
|
||||
|
||||
Reference in new issue
Block a user