I want to re-create the ls -AlF
program but in a way that I like myself, and I want to use NoFlo to do it.
This is the graph (graphs/ListDirectory.fbp
) that I made:
ReadDir(filesystem/ReadDir)
Stat(filesystem/Stat)
SplitByStatType(SplitByStatType)
Display(core/Output)
ReadDir OUT -> IN Stat
ReadDir ERROR -> IN Display
Stat OUT -> IN SplitByStatType
Stat ERROR -> IN Display
SplitByStatType DIRECTORY -> IN Display
SplitByStatType FILE -> IN Display
'.' -> SOURCE ReadDir
This is the component components/SplitByStatType.js
:
const noflo = require('noflo')
exports.getComponent = () => {
const component = new noflo.Component()
component.description = 'Splits directories and files.'
component.icon = 'directory'
component.inPorts.add('in', {
datatype: 'object',
})
component.outPorts.add('file', {
datatype: 'object',
})
component.outPorts.add('directory', {
datatype: 'object',
})
component.outPorts.add('blockdevice', {
datatype: 'object',
})
component.outPorts.add('characterdevice', {
datatype: 'object',
})
component.outPorts.add('fifo', {
datatype: 'object',
})
component.outPorts.add('socket', {
datatype: 'object',
})
component.outPorts.add('error', {
datatype: 'object',
})
component.process((input, output) => {
if (!input.hasData('in')) return
const data = input.getData('in')
const { isFile, isDirectory, isBlockDevice, isCharacterDevice, isFifo, isSocket } = data
if (isFile) {
output.send({
file: data,
})
}
if (isDirectory) {
output.send({
directory: data,
})
}
if (isBlockDevice) {
output.send({
blockdevice: data,
})
}
if (isCharacterDevice) {
output.send({
characterdevice: data,
})
}
if (isFifo) {
output.send({
fifo: data,
})
}
if (isSocket) {
output.send({
socket: data,
})
}
// TODO: Else, error?
output.done()
})
return component
}
- What would you call this component and/or has someone made it already?
- Can I do this without implementing my own component using other already existing components?
- How do I tie together the filename and the stat so that I can process it in another component and print one line for each?
What I want to end up with is one line per node with directories first (sorted and with a /) and files last (also sorted and files beginning with '.' first).