Socket
Socket
Sign inDemoInstall

fs-tree-diff

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-tree-diff

Backs out file tree changes


Version published
Weekly downloads
683K
decreased by-22.87%
Maintainers
4
Weekly downloads
 
Created

What is fs-tree-diff?

The fs-tree-diff npm package is used to efficiently compare and manage differences between two file system trees. It is particularly useful for tasks that involve synchronizing directories, detecting changes, and applying updates based on those changes.

What are fs-tree-diff's main functionalities?

Compare two directories

This feature allows you to compare two directories and generate a patch that represents the differences between them. The code sample demonstrates how to create two file system trees and calculate the patch.

const FSTree = require('fs-tree-diff');
const entriesA = FSTree.fromEntries([{ relativePath: 'file1.txt', mode: 0o100644, size: 123, mtime: new Date() }]);
const entriesB = FSTree.fromEntries([{ relativePath: 'file2.txt', mode: 0o100644, size: 456, mtime: new Date() }]);
const treeA = new FSTree({ entries: entriesA });
const treeB = new FSTree({ entries: entriesB });
const patch = treeA.calculatePatch(treeB);
console.log(patch);

Apply a patch to a directory

This feature allows you to apply a patch to a directory, effectively synchronizing it with another directory. The code sample demonstrates how to calculate a patch and then apply it to a file system tree.

const FSTree = require('fs-tree-diff');
const entriesA = FSTree.fromEntries([{ relativePath: 'file1.txt', mode: 0o100644, size: 123, mtime: new Date() }]);
const entriesB = FSTree.fromEntries([{ relativePath: 'file2.txt', mode: 0o100644, size: 456, mtime: new Date() }]);
const treeA = new FSTree({ entries: entriesA });
const treeB = new FSTree({ entries: entriesB });
const patch = treeA.calculatePatch(treeB);
FSTree.applyPatch(treeA, patch);
console.log(treeA.entries);

Generate entries from a directory

This feature allows you to generate entries from a directory, which can then be used to create a file system tree. The code sample demonstrates how to read a directory and generate entries for each file.

const FSTree = require('fs-tree-diff');
const fs = require('fs');
const path = require('path');
function generateEntries(dir) {
  const entries = [];
  fs.readdirSync(dir).forEach(file => {
    const filePath = path.join(dir, file);
    const stats = fs.statSync(filePath);
    entries.push({ relativePath: file, mode: stats.mode, size: stats.size, mtime: stats.mtime });
  });
  return entries;
}
const entries = generateEntries('./my-directory');
console.log(entries);

Other packages similar to fs-tree-diff

Keywords

FAQs

Package last updated on 04 May 2019

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