Skip to content

Commit

Permalink
Removed async from deps; added nodejs 18 to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamkou committed May 8, 2022
1 parent f1cd37f commit c15fa2c
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 242 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: ['lts/*', '0.12', '4', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17']
node-version: ['lts/*', '0.12', '4', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18']
# version 5 is glitching

steps:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2021 Kanstantsin Kamkou and contributors
Copyright (c) 2013-2022 Kanstantsin Kamkou and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ node-gelf - Graylog2 client library for Node.js. Pro - because of code-quality (
"gelf-pro": "~1.3" // see the "releases" section
}
```
```npm install gelf-pro``` (**ALL** node.js versions are supported [0.x to 18.x] :)

`npm install gelf-pro` (**ALL** node.js versions are supported [0.x to 18.x] :)

Library depends on: `lodash#~4.17`

## Initialization
```javascript
Expand Down
85 changes: 38 additions & 47 deletions lib/adapter/udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'use strict';

var _ = require('lodash'),
async = require('async'),
crypto = require('crypto'),
dgram = require('dgram'),
abstract = require('./abstract');
Expand Down Expand Up @@ -61,7 +60,7 @@ adapter.getArrayFromBuffer = function (buffer, maxSize) {

/**
* Sends a chunk to the server
* @param {Object} message
* @param {String} message
* @param {Function} callback
* @returns {adapter}
*/
Expand All @@ -82,55 +81,47 @@ adapter.send = function (message, callback) {
cbResults(err, bytesSentTotal);
});

async.waterfall(
[
function (cb) {
self.deflate(message, cb);
},
function (buf, cb) {
var chunks = self.getArrayFromBuffer(
buf, self.specification.chunkMaxLength[self.options.protocol]
),
chunksCount = chunks.length;

if (chunksCount > self.specification.chunkMaxCount) {
return cb(
new Error(
'A message MUST NOT consist of more than %d chunks'.replace(
'%d', self.specification.chunkMaxCount
)
)
);
}

var packetId = Array.prototype.slice.call(crypto.randomBytes(8)),
cbOnce = _.once(cb);
self.deflate(message, function (err, buf) {
if (err) { return cbResults(err, 0); }

for (var idx in chunks) {
if (isInterrupted) {
break;
}
var chunkMaxLength = self.specification.chunkMaxLength[self.options.protocol],
chunks = self.getArrayFromBuffer(buf, chunkMaxLength),
chunksCount = chunks.length;

var chunk = chunks[idx],
packet = buffer.from(
self.specification.magicBytes.concat(packetId, idx, chunksCount, chunk)
);
client.send(
packet, 0, packet.length, self.options.port, self.options.host,
function (err, bytesSent) {
if (err) { return cbOnce(err); }
bytesSentTotal += bytesSent;
/* istanbul ignore else */
if (idx >= chunksCount - 1) {
cbOnce(err, bytesSentTotal);
}
}
);
}
if (chunksCount > self.specification.chunkMaxCount) {
return cbResults(
new Error(
'A message MUST NOT consist of more than %d chunks'.replace(
'%d', self.specification.chunkMaxCount
)
)
);
}

var packetId = Array.prototype.slice.call(crypto.randomBytes(8));
for (var idx in chunks) {
if (isInterrupted) {
break;
}
],
cbResults
);

var chunk = chunks[idx],
packet = buffer
.from(self.specification.magicBytes.concat(packetId, idx, chunksCount, chunk));
client.send(
packet, 0, packet.length, self.options.port, self.options.host,
function (err, bytesSent) {
if (err) { return cbResults(err); }
bytesSentTotal += bytesSent;
/* istanbul ignore else */
if (idx >= chunksCount - 1) {
cbResults(err, bytesSentTotal);
}
}
);
}
});

return this;
};

Expand Down
Loading

0 comments on commit c15fa2c

Please sign in to comment.