bdistin / fs-nextra Goto Github PK
View Code? Open in Web Editor NEWNode.js fs.promises enhanced standard extra methods, atomic methods, and basic compression methods.
Home Page: https://fs-nextra.js.org
License: MIT License
Node.js fs.promises enhanced standard extra methods, atomic methods, and basic compression methods.
Home Page: https://fs-nextra.js.org
License: MIT License
I ran into problem with moving a folder for a physical drive to another (mounted) drive.
My application is running at D:\
.
fsn.move('source\dir', 'T:\target\dir')
Error: EXDEV: cross-device link not permitted, rename 'D:\source\dir' -> 'T:\target\dir'
{
errno: -4037,
code: 'EXDEV',
syscall: 'rename',
path: 'D:\source\dir',
dest: 'T:\target\dir'
}
The workaround is
fsn.move(path.resolve('source\dir'), 'T:\target\dir')
Here is my pull request
I checked the implementation of fsn.move, it seems source
and destination
are resolved on the fly, but not everywhere. Is there a particular reason for that?
Lines 26 to 44 in 928bb20
Hello,
It seems that exists
is not in fs/promises
in Node 10, so, must be manually checked and added as promisified version...
Branch | Build failing 🚨 |
---|---|
Dependency |
@types/node
|
Current Version | 10.1.2 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
While loading multiple json files using the json provider causes a memory leak, 10 small json files causes 1GB of memory then the memory keeps going up until it crashes nodejs.
const { Provider, util } = require('klasa');
const { resolve } = require('path');
const fs = require('fs-nextra');
module.exports = class extends Provider {
constructor(...args) {
super(...args);
this.baseDirectory = resolve(this.client.userBaseDirectory, 'bwd', 'provider', 'json');
}
/**
* Initializes the database
* @private
*/
async init() {
await fs.ensureDir(this.baseDirectory).catch(err => this.client.emit('error', err));
}
/* Table methods */
/**
* Checks if a directory exists.
* @param {string} table The name of the table you want to check
* @returns {Promise<boolean>}
*/
hasTable(table) {
return fs.pathExists(resolve(this.baseDirectory, table));
}
/**
* Creates a new directory.
* @param {string} table The name for the new directory
* @returns {Promise<void>}
*/
createTable(table) {
return fs.mkdir(resolve(this.baseDirectory, table));
}
/**
* Recursively deletes a directory.
* @param {string} table The directory's name to delete
* @returns {Promise<void>}
*/
deleteTable(table) {
return this.hasTable(table)
.then(exists => exists ? fs.emptyDir(resolve(this.baseDirectory, table)).then(() => fs.remove(resolve(this.baseDirectory, table))) : null);
}
/* Document methods */
/**
* Get all documents from a directory.
* @param {string} table The name of the directory to fetch from
* @param {string[]} [entries] The entries to download, defaults to all keys in the directory
* @returns {Object[]}
*/
async getAll(table, entries) {
if (!Array.isArray(entries) || !entries.length) entries = await this.getKeys(table);
if (entries.length < 5000) {
return Promise.all(entries.map(this.get.bind(this, table)));
}
const chunks = util.chunk(entries, 5000);
const output = [];
for (const chunk of chunks) output.push(...await Promise.all(chunk.map(this.get.bind(this, table))));
return output;
}
/**
* Get all document names from a directory, filter by json.
* @param {string} table The name of the directory to fetch from
* @returns {string[]}
*/
async getKeys(table) {
const dir = resolve(this.baseDirectory, table);
const filenames = await fs.readdir(dir);
const files = [];
for (const filename of filenames) {
if (filename.endsWith('.json')) files.push(filename.slice(0, filename.length - 5));
}
return files;
}
/**
* Get a document from a directory.
* @param {string} table The name of the directory
* @param {string} id The document name
* @returns {Promise<?Object>}
*/
get(table, id) {
return fs.readJSON(resolve(this.baseDirectory, table, `${id}.json`)).catch(() => null);
}
/**
* Check if the document exists.
* @param {string} table The name of the directory
* @param {string} id The document name
* @returns {Promise<boolean>}
*/
has(table, id) {
return fs.pathExists(resolve(this.baseDirectory, table, `${id}.json`));
}
/**
* Get a random document from a directory.
* @param {string} table The name of the directory
* @returns {Promise<Object>}
*/
getRandom(table) {
return this.getKeys(table).then(data => this.get(table, data[Math.floor(Math.random() * data.length)]));
}
/**
* Insert a new document into a directory.
* @param {string} table The name of the directory
* @param {string} document The document name
* @param {Object} data The object with all properties you want to insert into the document
* @returns {Promise<void>}
*/
create(table, document, data = {}) {
return fs.outputJSONAtomic(resolve(this.baseDirectory, table, `${document}.json`), { id: document, ...data });
}
/**
* Update a document from a directory.
* @param {string} table The name of the directory
* @param {string} document The document name
* @param {Object} data The object with all the properties you want to update
* @returns {void}
*/
async update(table, document, data) {
const existent = await this.get(table, document);
return fs.outputJSONAtomic(resolve(this.baseDirectory, table, `${document}.json`), util.mergeObjects(existent || { id: document }, this.parseUpdateInput(data)));
}
/**
* Replace all the data from a document.
* @param {string} table The name of the directory
* @param {string} document The document name
* @param {Object} data The new data for the document
* @returns {Promise<void>}
*/
replace(table, document, data) {
return fs.outputJSONAtomic(resolve(this.baseDirectory, table, `${document}.json`), { id: document, ...this.parseUpdateInput(data) });
}
/**
* Delete a document from the table.
* @param {string} table The name of the directory
* @param {string} document The document name
* @returns {Promise<void>}
*/
delete(table, document) {
return fs.unlink(resolve(this.baseDirectory, table, `${document}.json`));
}
};
This script above is part of klasa's master from their github which is used for loading the json files, but it uses fs-nextra.
I'm getting an errors, which only happens on Centos 7 when trying to deploy one project there from my local PC (running on windows)
at Object.<anonymous> (/home/iskovadiana95/discord/node_modules/klasa/node_modules/fs-nextra/dist/fs.js:5:39)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/iskovadiana95/discord/node_modules/klasa/node_modules/fs-nextra/dist/index.js:6:10
)
at Module._compile (module.js:653:30)```
And failed miserably:
`
node_modules/fs-nextra/typings/index.d.ts:141:11 - error TS2304: Cannot find name 'readJsonAtomic'.
141 export { readJsonAtomic as writeJSONAtomic };
~~~~~~~~~~~~~~
node_modules/fs-nextra/typings/index.d.ts:141:11 - error TS2552: Cannot find name 'readJsonAtomic'. Did you mean 'writeJsonAtomic'?
141 export { readJsonAtomic as writeJSONAtomic };`
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.travis.yml
package.json
files, so that was left aloneIf you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didn’t already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.