Research
Security News
Malicious npm Package Typosquats react-login-page to Deploy Keylogger
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
@file-storage/core
Advanced tools
Readme
____|_) | ___| |
| | | _ \\___ \ __| _ \ __| _` | _` | _ \
__| | | __/ | | ( | | ( | ( | __/
_| _|_|\___|_____/ \__|\___/ _| \__,_|\__, |\___|
A file system abstraction for Node.js |___/
A simple abstraction to interact with file system inspired by Laravel File System, provide one interface for many kind of drivers: local
, ftp
, sftp
, Amazon S3
, and Google Cloud Storage
, even your custom driver.
$ yarn add @file-storage/core @file-storage/common
# Or npm
$ npm install @file-storage/core @file-storage/common
And upload a file to local, it will be stored in storage
folder in your root project directory by default:
import Storage from '@file-storage/core';
// Upload from file path.
Storage.put('/my-image.png', '/path/of/destination/my-image.png');
// Or from a read-stream/buffer:
Storage.put(stream, '/path/of/destination/my-image.png');
By default only local driver is supported, if you want to use another driver, you need to install corresponding package:
yarn add @file-storage/s3
yarn add @file-storage/ftp
yarn add @file-storage/sftp
yarn add @file-storage/gcs
If there is no configuration, it will uploads to local disk. You can specific yours by using config
method:
import Storage from '@file-storage/core';
import { DriverName } from '@file-storage/common';
Storage.config({
// Default disk that you can access directly via Storage facade.
defaultDiskName: 'mys3',
diskConfigs: [
{
driver: DriverName.LOCAL,
name: 'local',
root: 'public',
},
{
driver: DriverName.S3,
name: 'mys3',
bucketName: 'mybucket',
// Uncomment if you want specify credentials manually.
// region: 'ap-southeast-1',
// credentials: {
// accessKeyId: '123abc',
// secretAccessKey: '123abc',
// },
},
],
});
// Somewhere in your code...
// Get file from s3:
Storage.get('/path/to/s3-bucket/my-image.png');
If you want to interact with a specific disk instead of the default, use disk
method to get that instance:
Storage.disk('local').get('/path/to/local/my-image.png');
Enable unique file name to prevent a file get replaced when uploading same file (or same name).
The unique name generated by uuid
to secure your file path.
Storage.config({
...
uniqueFileName: true,
});
// The uploaded path could be like this: /path/to/e8a3e633-fc7f-4dde-b7f0-d2686bcd6836.jpeg
If built-in drivers doesn't match your need, just defines a custom driver by extends Driver
abstract class:
import Storage from '@file-storage/core';
import { Driver } from '@file-storage/common';
interface OneDriveConfig {
name: string; // driver instance name is required.
...
}
class OneDrive extends Driver {
static readonly driverName = 'one_drive';
constructor(config: OneDriveConfig) {
super(config);
...
}
// Define all Driver's methods here.
}
And provide it to Storage.customDrivers:
Storage.config<OneDriveConfig>({
diskConfigs: [
{
driver: 'one_drive',
name: 'myCustomDisk',
...
}
],
customDrivers: [OneDrive],
});
If you want to upload image and also creates many diferent sizes for web resonsive, install this package, it is acting as a plugin, will generates those images automatically. Images will be generated if the size reach given breakpoints. We provide 3 breakpoints by default: large: 1000, medium: 750, small: 500. And the thumbnail is also generaged by default.
$ yarn add @file-storage/image-manipulation
NOTE: Image manipulation
only available on Storage facade, If you obtain a specific disk instance, set the second parameter to true
to obtain a storage instance insteads:
Storage.disk('your-disk', true); // Storage instance.
You can customize responsive formats and thumbnail size:
import ImageManipulation from '@file-storage/image-manipulation';
ImageManipulation.config({
breakpoints: {
size1: 500,
size2: 800,
},
thumbnailResizeOptions: {
width: 333,
height: 222,
fit: 'contain',
},
});
customDrivers
option: provides disk defination is enough.customDrivers
option, pass custom driver class directly to diskConfigs.driver
.MIT
FAQs
Unknown package
We found that @file-storage/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
Security News
The JavaScript community has launched the e18e initiative to improve ecosystem performance by cleaning up dependency trees, speeding up critical parts of the ecosystem, and documenting lighter alternatives to established tools.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.