question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any way to use in memory, without writing to a file?

See original GitHub issue

I would like to be able to do something like:

const minify = require('@node-minify/core');

const html = `
<!doctype html>
<html ${htmlAttributes}>
    <head>
        <meta charset="utf-8">
        <!-- ... -->
    </head>
</html>
`

console.log(minify(html))

Although on all the examples I see you have to pass in a file and output a file. Is it possible to do it in memory like above?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
srodcommented, May 15, 2019

Good idea, I will see that 👍

1reaction
srodcommented, Nov 3, 2019

It’s live in 5.1.0 You can use it like that:

const html = `
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
    </head>
</html>
`;

minify({
  compressor: htmlMinifier,
  content: html,
  options: {
    minifyJS: false
  },
  callback: function(err, min) {
    console.log('callback min');
    console.log(min);
  }
}).then(function(min) {
  console.log('html min');
  console.log(min);
});

You need to pass the compressor according the content (html, css, javascript). I will see if I can find a solution to detect content type and use defaults compressors.

You can also still pass options to the compressor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading then writing to a file without using memory (in place ...
I am aware that I can use buffers and reuse memory to minimize memory consumption, then use fseek -> Read -> Write till...
Read more >
13. Files — How to Think Like a Computer Scientist
To use a notebook, it has to be opened. When done, it has to be closed. While the notebook is open, it can...
Read more >
Reading, Writing, and Creating Files (The Java™ Tutorials ...
You can use the newBufferedWriter(Path, Charset, OpenOption...) method to write to a file using a BufferedWriter . The following code snippet shows how...
Read more >
writemem (Write Memory to File) - Windows drivers
The .writemem command writes a section of memory to a file. dbgcmd. Copy.
Read more >
Performing Memory File I/O Operations - IBM
This chapter describes how to perform memory file I/O operations. LE/VSE C Run-Time supports files known as memory files. Memory files are temporary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found