hyperlink / crc2json Goto Github PK
View Code? Open in Web Editor NEWNodeJS module/cli that scan a directory of files and generates a CRC32 for each file and outputs them in JSON format.
License: MIT License
NodeJS module/cli that scan a directory of files and generates a CRC32 for each file and outputs them in JSON format.
License: MIT License
It seems like the usage of callbacks is asynchronous in that events are getting hung up and are not completing prior to the next invocation.
I've got a scenario in which I've got two files I want to compare: A
(source) and B
(destination). I was able to more or less orchestrate this by wrapping a handler around the core c2cjson
which accepts not only the target directory and file info but also a callback which gets invoked when the desired file is discovered.
I invoke the same in a nested manner via the callback in order to discover B
CRC. And, after a couple of comparisons deciding whether a file was being added or potentially updated, then I want to respond with subsequent processing.
// i.e. file names to consider for copy from source directory to destination directory.
var items = [
{ name: "1" },
{ name: "2" },
{ name: "3" }
];
What I am finding is that these callbacks are still resolving after the main files loop, which leaves me wanting to do some "last" comparisons on the array of intended files. Sometimes it works, sometimes it does not; I just had an instance where file 1 and file 3 were flagged as adding, but file 2 was not, for instance.
var processPathCrc = (rootDir, info, callback) => {
crc2json(rootDir,
map => {
var value = undefined;
for (var k in map) {
if (k.endsWith(info.name)) {
value = map[k];
break;
}
}
callback(info, value);
});
};
All this to say, I really need a synchronous version, preferably on in which I can target a specific file, not necessarily the entire directory. That would really work best in my scenario, without having to worry, much less wonder, about nested callbacks and functional wrappers.
With example usage in my scenario. I translated from my Gulpfile
, so I think this is accurate, but I will correct it if necessary:
// Assuming i is a loop iterator
var last = items[items.length - 1];
var addSrcs = [];
var srcDir = "/path/to/src";
var destDir = "/path/to/dest";
// This is incomplete code; assuming an outer file items loop with i iterator.
processPathCrc(srcDir,
items[i],
(a, x) => {
processPathCrc(destDir,
a,
(b, y) => {
var src = path.join(srcDir, b.name).replace(/\\/g, "/");
var dest = path.join(destDir, b.name).replace(/\\/g, "/");
b.adding = x && y === undefined;
b.updating = x && y && x !== y;
if (b.adding) {
addSrcs.push(b.name);
}
// Using fs-jetpack, or your favorite, file system package.
fs.copy(src, dest, { overwrite: b.adding || b.updating });
if (b=== last) {
archive();
}
});
});
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.