🧩
Seanime Extensions
🧩
Seanime Extensions
  • Seanime
    • Getting started
    • Core APIs
    • Changelog
  • Content Providers
    • Write, test, share
    • Anime torrent provider
    • Manga provider
    • Online streaming provider
  • Plugins
    • Introduction
    • Write, test, share
    • APIs
      • Helpers
      • Store
      • Storage
      • Database
      • AniList
      • System
        • Permissions
        • OS
        • Filepath
        • Commands
        • Buffers, I/O
        • MIME
    • UI
      • Basics
      • User Interface
        • Tray
        • Toast
        • Screen
        • Command Palette
        • Action
        • DOM
      • Anime/Library
        • Anime
        • Playback
        • Continuity
        • Auto Downloader
        • Auto Scanner
        • Filler Manager
        • External Player Link
      • Downloading
        • Downloader
        • Torrent Client
      • Other
        • Manga
        • Discord
        • MPV
    • Hooks
    • Example
  • Frequently asked
    • Feature requests
Powered by GitBook
On this page
  • $os
  • Info
  • Directories
  • File operations
  • $osExtra
  • Directories
  • Unarchive files
  1. Plugins
  2. APIs
  3. System

OS

OS-agonistic APIs for operating system functionality, such as interacting with the filesystem.

PreviousPermissionsNextFilepath

Last updated 2 months ago

Go reference:

$os

Info

console.log("Platform:", $os.platform); // darwin
console.log("Arch:", $os.arch); // arm64

Directories

$os.tempDir() // $TEMP must be in the allow list
$os.cacheDir() // $CACHE must be in the allow list
$os.configDir() // $CONFIG must be in the allow list
$os.homeDir() // $HOME must be in the allow list

File operations

Always call close() once you're done manipulating a file.

Example
// C:\Users\user\Downloads\test.txt
Hello World!

// my-plugin.ts
// "C:/Users/user/Downloads/**/*" and "$TEMP/**/*" have been added to 'allowReadPaths' and 'allowWritePaths'

// Access the temp directory
const tempDirPath = $os.tempDir();
console.log("Temp dir:", tempDirPath);

// Read files
const content = $os.readFile("C:\Users\user\Downloads\test.txt");
console.log("File content:", $toString(content)); // Hello World!

// Write/create files
$os.writeFile("C:\Users\user\Downloads\test.txt.new", $toBytes("New content"), 0644);
const newContent = $os.readFile("C:\Users\user\Downloads\test.txt.new");
console.log("New file content:", $toString(newContent)); // New content

// Read directories
const entries = $os.readDir("C:\Users\user\Downloads");
for (const entry of entries) {
	console.log(entry.name()); // test.txt, test.txt.new
}

// Create directories
$os.mkdir("C:\Users\user\Downloads\newdir", 0755);
const newEntries = $os.readDir("C:\Users\user\Downloads");
for (const entry of newEntries) {
	console.log(entry.name()); // test.txt, test.txt.new, newdir
}

// Rename files
$os.rename("C:\Users\user\Downloads\test.txt.new", "C:\Users\user\Downloads\test.txt.renamed");
let renameSuccess = true
try {
	// File exists, no error thrown
	$os.stat("C:\Users\user\Downloads\test.txt.renamed");
} catch(e) {
	renameSuccess = false
}
console.log(renameSuccess); // true

// Remove files
$os.remove("C:\Users\user\Downloads\test.txt.renamed");
let removeSuccess = true;
try {
	$os.stat("C:\Users\user\Downloads\test.txt.renamed");
	removeSuccess = false;
} catch (e) {
	// Error thrown becuase file should not exist
	removeSuccess = true;
}
console.log(removeSuccess); // true

$osExtra

This API gives you additional functionalities

Directories

$osExtra.desktopDir() // $DESKTOP must be in the allow list
$osExtra.documentDir() // $DOCUMENT must be in the allow list
$osExtra.downloadDir() // $DOWNLOAD must be in the allow list

Unarchive files

  • unzipFile, unrarFile

// If "file.zip" contains `folder > file.text`
$osExtra.unzipFile("/path/to/downloaded/file.zip", "/path/to/dest") 
// -> "/path/to/dest/folder/file.txt"

// If "file.rar" contains `file.txt`
$osExtra.unrarFile("/path/to/downloaded/file.zip", "/path/to/dest")
// -> "/path/to/dest/file.txt"
https://pkg.go.dev/os