fs

Corrupt/truncated mp4 upload to S3 bucket using NodeJS and AWS S3

北城以北 提交于 2019-12-24 05:24:05
问题 I'm using fs.readFile to read in a local mp4 file of around 700KB, and AWS SDK to load the file onto my S3 bucket. The process works, but the file is corrupt, presumably truncated because the size of the resulting file on S3 is only around 500KB. The code I'm using works for images just fine. Just not working for mp4 files. Here's my code: fs.readFile(file_location, function (err, data) { if (err) { console.log('fs error': err); } else { var base64data = new Buffer(data, 'binary'); var params

Making my own “database” using Node and FS

怎甘沉沦 提交于 2019-12-24 04:12:09
问题 So I'm trying to make a database, couple of function snippets that read, write or create X.json files. The way I imagined it to be is a DB folder, then within that folder bunch of username folders, and there, a bunch of files, like account.json, level.json, and so on... So each folder would keep users data, now, this is the code I managed to write so far, and it works. But the problem is, on the FS docs, it says that using fs.stat to check for the existence of the file before reading/writing

Making my own “database” using Node and FS

倾然丶 夕夏残阳落幕 提交于 2019-12-24 04:11:12
问题 So I'm trying to make a database, couple of function snippets that read, write or create X.json files. The way I imagined it to be is a DB folder, then within that folder bunch of username folders, and there, a bunch of files, like account.json, level.json, and so on... So each folder would keep users data, now, this is the code I managed to write so far, and it works. But the problem is, on the FS docs, it says that using fs.stat to check for the existence of the file before reading/writing

Node.js WriteStream doesn't write data to file until closed

痞子三分冷 提交于 2019-12-24 02:52:45
问题 How can I cause the data to be written to the file as WriteStream.write() is called? Edit: As it turns out, this works when I use the REPL and call the function. However, this doesn't work in my program: import * as FS from "fs"; import { LetterGroup } from "./LetterGroup"; import { Dictionary } from "./Dictionary"; import { Word } from "./Word"; import * as OS from "os"; const groups: Array<LetterGroup> = LetterGroup.letterGroupsFromString(FS.readFileSync("./letterGroups.txt").toString());

Using readFileSync after creating a file with createWriteStream shows empty buffer

十年热恋 提交于 2019-12-24 01:45:54
问题 I am using the gif-encoder npm module to create a gif, then the imgur-uploader module to upload it to imgur. Below is my relevant code, where pics is an array of filenames: var gif = new GifEncoder(imageSize, imageSize); var file = fs.createWriteStream('testing.gif'); gif.pipe(file); gif.setRepeat(0); gif.setQuality(20); gif.setDelay(100); gif.writeHeader(); var addToGif = function(images, counter = 0) { getPixels(images[counter], function(err, pixels) { gif.addFrame(pixels.data); gif.read();

java 遍历指定目录下的所有目录

南笙酒味 提交于 2019-12-23 09:43:40
public static void main ( String [ ] args ) { t10 ( ) ; } //遍历指定目录下的所有目录 public static void t10 ( ) { File dir = new File ( "F:\\IOTest_zx\\one" ) ; File [ ] fs = dir . listFiles ( ) ; FileFilter filter = new FileFilter ( ) { @Override public boolean accept ( File pathname ) { return pathname . isDirectory ( ) ; } } ; fs = dir . listFiles ( filter ) ; System . out . println ( fs . length ) ; if ( fs . length == 0 ) { System . out . println ( "目录不存在或它不是一个目录" ) ; } else { for ( int i = 0 ; i < fs . length ; i ++ ) { File fileName = fs [ i ] ; System . out . println ( fileName . toString ( ) ) ;

Uncaught TypeError: Cannot read property 'prototype' of undefined Meteor-File Package

混江龙づ霸主 提交于 2019-12-23 05:27:54
问题 I have a problem when using this documentation: https://github.com/VeliovGroup/Meteor-Files/wiki/Image-Processing. This doc guides about create thumbnail images for pakage Meteor-File I installed all need package like the guiding, but when I run code, it had a problem: Uncaught TypeError: Cannot read property 'prototype' of undefined at patch (modules.js?hash=b849b729a9c5ee343b208254dca34d866ee59991:19084) at graceful-fs.js (modules.js?hash=b849b729a9c5ee343b208254dca34d866ee59991:18945) at

NodeJS: Confusion about async “readdir” and “stat”

坚强是说给别人听的谎言 提交于 2019-12-23 03:44:09
问题 In the docs it shows two versions of readdir and stat. Both of which have an async and sync version readir/readdirSync and stat/statSync . Because readidir and stat are async I would expect them to return a Promise but when trying to use async/await the script doesnt wait for readdir to resolve and if I use .then/.catch I get an error cannot read .then of undefined . All I'm trying to do here is map the directories that exist inside of the directory the script is being ran inside of to the

Node-Webkit Download PDF

孤者浪人 提交于 2019-12-23 03:16:39
问题 I'm building a node-webkit app where I receive a request from a website to download a particular file. When I initiate the web service call I get back the file in the response.body. I'm trying to use the example in the fs api to save the pdf to my local folder i.e.: (i'm passing the response.body into the data field, and passing a string 'binary' to specify encoding under options) var options = { encoding: 'binary' }; console.log('File name:' + fileName); fileOperations.write(fileName,

Returning the content of multiple files in node.js

大憨熊 提交于 2019-12-23 01:21:06
问题 Im using the fs module of node.js to read all the files of a directory and return their content, but the array i use to store the content is always empty. server-side: app.get('/getCars', function(req, res){ var path = __dirname + '/Cars/'; var cars = []; fs.readdir(path, function (err, data) { if (err) throw err; data.forEach(function(fileName){ fs.readFile(path + fileName, 'utf8', function (err, data) { if (err) throw err; files.push(data); }); }); }); res.send(files); console.log('complete