Giter Site home page Giter Site logo

bdistin / fs-nextra Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 7.0 3.51 MB

Node.js fs.promises enhanced standard extra methods, atomic methods, and basic compression methods.

Home Page: https://fs-nextra.js.org

License: MIT License

TypeScript 100.00%
fs atomics typescript promises

fs-nextra's People

Contributors

appellation avatar bdistin avatar codacy-badger avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar greenkeeper[bot] avatar kyranet avatar pyrotechniac avatar tech6hutch avatar tinovyatkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fs-nextra's Issues

Move operation error "EXDEV: cross-device link not permitted, rename"

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?

export async function move(source: string, destination: string, options: MoveOptions = {}): Promise<void> {
const overwrite = options.overwrite || false;
if (resolve(source) === resolve(destination)) return fsp.access(source);
const myStat = await fsp.lstat(source);
if (myStat.isDirectory() && isSrcKid(source, destination)) {
throw new Error('FS-NEXTRA: Moving a parent directory into a child will result in an infinite loop.');
}
await mkdirs(dirname(destination));
if (overwrite) {
await remove(destination);
} else if (await pathExists(destination)) {
throw new Error('FS-NEXTRA: Destination already exists.');
}
try {
return await fsp.rename(source, destination);

exists

Hello,

It seems that exists is not in fs/promises in Node 10, so, must be manually checked and added as promisified version...

An in-range update of @types/node is breaking the build 🚨

Version 10.1.3 of @types/node was just published.

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.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build passed Details
  • Codacy/PR Quality Review Hang in there, Codacy is reviewing your Pull request. Details
  • continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

[closed verified as bug with klasa] Memory leak while reading multiple json

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.

TypeError: Cannot read property 'access' of undefined

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)```

Just installed it

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 };`

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If 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.

More information on this issue

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 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.