Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flowfuse/nr-file-nodes

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flowfuse/nr-file-nodes - npm Package Compare versions

Comparing version 0.0.5-479584e-202310241453.0 to 0.0.5-8fd0d22-202311081409.0

215

file.js

@@ -66,3 +66,3 @@ /**

function processMsg (msg, nodeSend, done) {
let filename = node.filename || ''
const filename = node.filename || ''
// Pre V3 compatibility - if filenameType is empty, do in place upgrade

@@ -84,5 +84,8 @@ if (typeof node.filenameType === 'undefined' || node.filenameType === '') {

} else {
filename = value
completeProcessMsg(msg, nodeSend, value, done)
}
})
}
function completeProcessMsg (msg, nodeSend, filename, done) {
filename = filename || ''

@@ -267,57 +270,69 @@ msg.filename = filename

}
let propertyError = false
RED.util.evaluateNodeProperty(node.filename, node.filenameType, node, msg, (err, value) => {
if (err) {
node.error(err, msg)
propertyError = true
// return done()
return nodeDone()
} else {
filename = (value || '').replace(/\t|\r|\n/g, '')
completeProcessMsg(msg, nodeSend, filename, nodeDone)
}
})
if (propertyError) {
return
}
filename = filename || ''
let fullFilename = filename
function completeProcessMsg (msg, nodeSend, filename, nodeDone) {
filename = filename || ''
let fullFilename = filename
if (filename && RED.settings.fileWorkingDirectory && !path.isAbsolute(filename)) {
// fullFilename = path.resolve(path.join(RED.settings.fileWorkingDirectory, filename))
fullFilename = path.join(RED.settings.fileWorkingDirectory, filename)
}
if (!node.filename) {
node.status({ fill: 'grey', shape: 'dot', text: filename })
}
if (path.isAbsolute(fullFilename)) {
fullFilename = fullFilename.slice(1)
}
if (filename === '') {
node.warn(RED._('file.errors.nofilename'))
nodeDone()
} else {
msg.filename = filename
let lines = Buffer.from([])
let spare = ''
let count = 0
let type = 'buffer'
let ch = ''
if (node.format === 'lines') {
ch = '\n'
type = 'string'
if (filename && RED.settings.fileWorkingDirectory && !path.isAbsolute(filename)) {
// fullFilename = path.resolve(path.join(RED.settings.fileWorkingDirectory, filename))
fullFilename = path.join(RED.settings.fileWorkingDirectory, filename)
}
let getout = false
if (!node.filename) {
node.status({ fill: 'grey', shape: 'dot', text: filename })
}
if (path.isAbsolute(fullFilename)) {
fullFilename = fullFilename.slice(1)
}
if (filename === '') {
node.warn(RED._('file.errors.nofilename'))
nodeDone()
} else {
msg.filename = filename
let lines = Buffer.from([])
let spare = ''
let count = 0
let type = 'buffer'
let ch = ''
if (node.format === 'lines') {
ch = '\n'
type = 'string'
}
let getout = false
const rs = fs.createReadStream(fullFilename)
.on('readable', function () {
let chunk
let m
const hwm = rs._readableState.highWaterMark
while ((chunk = rs.read()) !== null) {
if (node.chunk === true) {
getout = true
if (node.format === 'lines') {
spare += decode(chunk, node.encoding)
const bits = spare.split('\n')
let i = 0
for (i = 0; i < bits.length - 1; i++) {
const rs = fs.createReadStream(fullFilename)
.on('readable', function () {
let chunk
let m
const hwm = rs._readableState.highWaterMark
while ((chunk = rs.read()) !== null) {
if (node.chunk === true) {
getout = true
if (node.format === 'lines') {
spare += decode(chunk, node.encoding)
const bits = spare.split('\n')
let i = 0
for (i = 0; i < bits.length - 1; i++) {
m = {}
if (node.allProps === true) {
m = RED.util.cloneMessage(msg)
} else {
m.topic = msg.topic
m.filename = msg.filename
}
m.payload = bits[i]
m.parts = { index: count, ch, type, id: msg._msgid }
count += 1
nodeSend(m)
}
spare = bits[i]
}
if (node.format === 'stream') {
m = {}

@@ -330,70 +345,56 @@ if (node.allProps === true) {

}
m.payload = bits[i]
m.payload = chunk
m.parts = { index: count, ch, type, id: msg._msgid }
count += 1
if (chunk.length < hwm) { // last chunk is smaller that high water mark = eof
getout = false
m.parts.count = count
}
nodeSend(m)
}
spare = bits[i]
} else {
lines = Buffer.concat([lines, chunk])
}
if (node.format === 'stream') {
m = {}
if (node.allProps === true) {
m = RED.util.cloneMessage(msg)
} else {
m.topic = msg.topic
m.filename = msg.filename
}
m.payload = chunk
m.parts = { index: count, ch, type, id: msg._msgid }
count += 1
if (chunk.length < hwm) { // last chunk is smaller that high water mark = eof
getout = false
m.parts.count = count
}
nodeSend(m)
}
} else {
lines = Buffer.concat([lines, chunk])
}
}
})
.on('error', function (err) {
node.error(err, msg)
if (node.sendError) {
const sendMessage = RED.util.cloneMessage(msg)
delete sendMessage.payload
sendMessage.error = err
nodeSend(sendMessage)
}
nodeDone()
})
.on('end', function () {
if (node.chunk === false) {
if (node.format === 'utf8') {
msg.payload = decode(lines, node.encoding)
} else { msg.payload = lines }
nodeSend(msg)
} else if (node.format === 'lines') {
let m = {}
if (node.allProps) {
m = RED.util.cloneMessage(msg)
} else {
m.topic = msg.topic
m.filename = msg.filename
})
.on('error', function (err) {
node.error(err, msg)
if (node.sendError) {
const sendMessage = RED.util.cloneMessage(msg)
delete sendMessage.payload
sendMessage.error = err
nodeSend(sendMessage)
}
m.payload = spare
m.parts = {
index: count,
count: count + 1,
ch,
type,
id: msg._msgid
nodeDone()
})
.on('end', function () {
if (node.chunk === false) {
if (node.format === 'utf8') {
msg.payload = decode(lines, node.encoding)
} else { msg.payload = lines }
nodeSend(msg)
} else if (node.format === 'lines') {
let m = {}
if (node.allProps) {
m = RED.util.cloneMessage(msg)
} else {
m.topic = msg.topic
m.filename = msg.filename
}
m.payload = spare
m.parts = {
index: count,
count: count + 1,
ch,
type,
id: msg._msgid
}
nodeSend(m)
} else if (getout) { // last chunk same size as high water mark - have to send empty extra packet.
const m = { parts: { index: count, count, ch, type, id: msg._msgid } }
nodeSend(m)
}
nodeSend(m)
} else if (getout) { // last chunk same size as high water mark - have to send empty extra packet.
const m = { parts: { index: count, count, ch, type, id: msg._msgid } }
nodeSend(m)
}
nodeDone()
})
nodeDone()
})
}
}

@@ -400,0 +401,0 @@ })

{
"name": "@flowfuse/nr-file-nodes",
"version": "0.0.5-479584e-202310241453.0",
"version": "0.0.5-8fd0d22-202311081409.0",
"description": "Node-RED file nodes packaged for FlowFuse",

@@ -5,0 +5,0 @@ "main": "index.js",

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