GithubHelp home page GithubHelp logo

Comments (3)

dsherret avatar dsherret commented on May 16, 2024 1

So from my basic understanding (just going to write this out to ensure I'm on the right page) this isn't an sh feature and is something found in other shells like bash. It requires creating a pipe containing the string's contents and passing the file descriptor of that pipe as an argument to the diff subprocess. For this to work in dax there would need to be a way in Deno of creating named pipes and then providing those to subprocesses as arguments (it's something that's been discussed in the past and I think we could do it).

Looking at diff, it seems like there isn't a way to just provide it two strings as arguments. This is the best I can do in this scenario for the time being, which is slightly unfortunate:

async function diff(a: string, b: string) {
  async function makeTempFile() {
    const filePath = await Deno.makeTempFile();
    return $.path(filePath);
  }

  const [temp1, temp2] = await Promise.all([makeTempFile(), makeTempFile()]);
  try {
    await Promise.all([temp1.writeText(a), temp2.writeText(b)]);
    await $`diff ${temp1} ${temp2}`;
  } finally {
    await Promise.all([temp1.remove(), temp2.remove()]);
  }
}

const a = "12345"
const b = "23456"
await diff(a, b);

from dax.

char8x avatar char8x commented on May 16, 2024

Thank you for sharing your understanding. You are correct that this feature isn't native to sh and is more commonly found in shells like bash. I appreciate your insight into the potential solution for Dax, and I agree that having the capability to create named pipes in Deno and passing them as arguments to subprocesses would be a valuable addition.

from dax.

makidoll avatar makidoll commented on May 16, 2024

I was wondering if it would be possible to instead set fds ourselves. For example, imagemagick lets you run something like convert fd:3 fd:4 to take data from pipe 3 and 4 to use. Here's an example of it for a different project in node.

https://github.com/makidoll/frog-bot/blob/ebd80eca7514a65607927c294faf102698d67f34/src/image-utils.ts#L234

from dax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.