sindresorhus / temp-write Goto Github PK
View Code? Open in Web Editor NEWWrite string/buffer/stream to a random temp file
License: MIT License
Write string/buffer/stream to a random temp file
License: MIT License
Does this work on Windows? This does work on Windows. You're not using a Windows-based CI (AppVeyor) for anyone to see if tests pass.
Remove the callback and add promises.
Will add a PR for this (which includes AVA for testing).
I can't use this module because filename is not descriptive enough. For instance, this is perfect readable:
/var/folders/j3/5b59rnl11p98dhkyfv5b9nkr0000gn/T/1396396004094.2021/client/app/js/main.js:12: WARNING - app.ok is never defined
>> return console.log(app.ok());
while this is no go:
/var/folders/j3/5b59rnl11p98dhkyfv5b9nkr0000gn/T/3a4238c7-cfb2-48a7-a413-194a7adcb962/59rnl11p98dhkyfv5b9n.js:11: ERROR - variable global is undeclared
return global.React = require('react');
Which file failed? I don't know.
Or is it just up to the user whenever they do their usual temp file cleanup?
Hello, I apologise for this question as it may be unrelated to your code and more because of my inexperience with JavaScript modules.
Recently I changed from temp-write
4.x to 5.x and encountered the following error:
Cannot use import statement outside a module
/Users/samuel/.atom/packages/script-runner/node_modules/temp-write/index.js:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { import {promisify} from 'node:util';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at new Script (vm.js:84:7)
It seems like maybe I'm using this incorrectly? But going back to 4.x the error goes away.
Would you be open to allowing input
to be a stream?
In an Electron app, I have a little save-url
module that looks like this:
const fs = require('fs');
const path = require('path');
const got = require('got');
const tempfile = require('tempfile');
const saveUrl = (urlStr) => {
const filePath = tempfile(path.extname(urlStr));
return new Promise((resolve, reject) => {
got.stream(urlStr)
.pipe(fs.createWriteStream(filePath))
.on('error', reject)
.on('finish', () => {
resolve(filePath);
});
});
};
I based this on some very similar code from you in wallpaper-cli
.
Both of these would benefit if temp-write
supported taking a stream as input
.
In my case, my module would be reduced to:
const path = require('path');
const got = require('got');
const tempWrite = require('temp-write');
const saveUrl = (urlStr) => {
return tempWrite(got.stream(urlStr), path.basename(urlStr));
};
I get the following error:
Uncaught Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\MyApp\node_modules\temp-write\index.js
I Use Latest NodeJS: 16.2.0
I Use Latest temp-write: 5.0.0
❯ node --version
v7.4.0
❯ node -pe 'os.tmpdir()'
/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
❯ node -pe 'fs.realpathSync(os.tmpdir())'
/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
When writing a Node.js module using temp-write
, __filename
inside that module is different than the file path that is returned by temp-write
.
Using macOS Sierra 10.12.3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.