Socket
Socket
Sign inDemoInstall

simple_video_response

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

35

express.js

@@ -26,15 +26,22 @@ "use strict";

const onClose = () => {
if (callback && typeof callback === "function") {
callback(err);
}
return new Promise(async (resolve, reject) => {
if (video && video.statusCode === 206) {
video.body.destroy();
}
const onClose = () => {
if (callback && typeof callback === "function") {
callback(err);
}
video = null;
};
if (video && video.statusCode === 206) {
video.body.destroy();
}
return (async () => {
video = null;
if (err) {
reject(err);
} else {
resolve();
}
};
try {

@@ -46,3 +53,3 @@ video = await videoStreamResponse(videoFilePath, req.headers.range, options);

}
res.statusCode = video.statusCode;

@@ -59,2 +66,6 @@ if (video.statusCode === 206) {

video.body.on("close", onClose);
video.body.on("error", (err) => {
err = e;
onClose();
});
} else {

@@ -64,3 +75,3 @@ onClose();

}
})();
});
};

@@ -67,0 +78,0 @@

{
"name": "simple_video_response",
"version": "0.0.1",
"version": "0.0.2",
"description": "video response",

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

@@ -8,7 +8,10 @@

let DEFAULT_STREAM_OPTIONS = {
basePath: null,
maxChunkSize: Number.MAX_SAFE_INTEGER,
};
const isDebug = (() => {
if (require('inspector').url()) {
return true;
}
return false;
})();
const fileCache = {};

@@ -25,2 +28,11 @@

// size, ext
const loadFileSizeAndExt = async (filePath) => {
const fileStat = await fsStat(filePath);
const ext = getExt(filePath);
return {
size: fileStat.size,
ext: ext,
};
};
const getFileSizeAndExt = async (filePath) => {

@@ -32,9 +44,3 @@ const cacheStat = fileCache[filePath];

const fileStat = await fsStat(filePath);
const ext = getExt(filePath);
const info = {
size: fileStat.size,
ext: ext,
};
const info = await loadFileSizeAndExt(filePath);
fileCache[filePath] = info;

@@ -44,9 +50,14 @@ return info;

let DEFAULT_STREAM_OPTIONS = {
basePath: "",
fileStatCache: isDebug,
maxChunkSize: Number.MAX_SAFE_INTEGER,
fileSizeAndExtFn: null,
};
const videoStreamResponse = async (filePath, httpRangeHeader, options) => {
options = Object.assign({}, DEFAULT_STREAM_OPTIONS, options);
if (options.basePath) {
filePath = path.join(String(options.basePath), filePath);
}
const fileInfo = await getFileSizeAndExt(filePath);
filePath = path.join(String(options.basePath), filePath);
const fileInfo = await options.fileSizeAndExtFn(filePath);
const fileSize = fileInfo.size;

@@ -62,3 +73,3 @@ const contentType = "video/" + fileInfo.ext;

},
body: "",
body: " ",
};

@@ -91,3 +102,10 @@ }

DEFAULT_STREAM_OPTIONS = Object.assign({}, DEFAULT_STREAM_OPTIONS, defaultOptions);
if (DEFAULT_STREAM_OPTIONS.fileStatCache) {
DEFAULT_STREAM_OPTIONS.fileSizeAndExtFn = getFileSizeAndExt;
} else {
DEFAULT_STREAM_OPTIONS.fileSizeAndExtFn = loadFileSizeAndExt;
}
return videoStreamResponse;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc