New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tspace-nfs

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tspace-nfs

tspace-nfs is a Network File System (NFS) and provides both server and client capabilities for accessing files over a network.

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
64
decreased by-48.39%
Maintainers
0
Weekly downloads
 
Created
Source

tspace-nfs

NPM version NPM downloads

tspace-nfs is a NFS stands for Network File System and provides both server and client capabilities for accessing files over a network.

Install

Install with npm:

npm install tspace-nfs --save

Basic Usage

Server

import { NfsServer } from "tspace-nfs";

new NfsServer()
.onCredentials(async ({ token , secret , bucket }) => {

  // In this simple example, you can use any database as a wrapper to check the credentials.
  const lists = [
    {
      token: 'token-dev',
      secret: 'secret-dev',
      bucket : 'dev'
    }
  ]
  return lists.every(list => list.bucket === bucket && list.secret === secret && list.token === token)
})
.defaultPage(`<b> hello nfs-server! </b>`)
.directory('nfs')
.credentials({
  expired : 1000 * 60 * 60 * 24, // by default 1 hour
  secret  : 'credential-secret'
}) // the credentials will auto refresh every expired
fileExpired(60 * 15) // 15 minutes by default 1 hour
.listen(8000 , ({ port }) => console.log(`Server is running on port http://localhost:${port}`))

Client

import { NfsClient } from "tspace-nfs";

const nfs = new NfsClient({
  token     : '<YOUR TOKEN>',   // token
  secret    : '<YOUR SECRET>',  // secret
  bucket    : '<YOUR BUCKET>',  // bucket name
  url       : '<YOUR URL>'      // https://nfs-server.example.com
})
.onError((err, nfs) => {
  console.log('nfs client failed to connect')
  console.log(err.message)
  nfs.quit()
})
.onConnect((nfs) => {
  console.log('nfs client connected')
})

(async () => {

  const fileDirectory = 'my-cat.png'

  const url = await nfs.toURL(fileDirectory , { download : false }) // default download true

  const base64 = await nfs.toBase64(fileDirectory)

  const stream = await nfs.toStream(fileDirectory)

  const file = files[0] // assume the file from your upload

  await nfs.upload({
    directory : file.tempFilePath,
    name : 'my-video.mp4',
    folder : 'my-folder'
  })

  const deleted = await nfs.delete(fileDirectory)

  const storage = await nfs.storage()

})()

Keywords

FAQs

Package last updated on 17 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc