andykais
recommended way to get file checksum
Hi, I am creating an application that needs to get checksums for files. The code currently looks like this:
This is fairly though. A ~1GB file will take around 3 minutes to generate a checksum with the code above, whereas the built in linux utility
sha256sum
can do the same in 2.5 seconds. Parallelizing this isnt straightforward to me though, since the hash update is blocking3 replies
How to detect when --watch flag has been passed to `deno run` programatically?
I am writing a small cli script, and I have a few bits of code that do not play nicely with
deno run --watch <script>
. (e.g. Deno.addSignalListener('SIGINT', graceful_shutdown)
. What I want to do is only set up that listener when I am running my cli app in 'production mode'. E.g. while I am developing the cli app with --watch
I do not want to set up shutdown listeners. Is there a way to accomplish this with the Deno
global perhaps? My current workaround is to pass some custom flag to my cli script when I am in development, like --mode=development
or --no-signal
, but this is a bit confusing for users because this flag is only important for development.3 replies
best practice when spawning commands that require sudo?
I am building a command line utility in deno that leverages data coming from
tcpdump
. To get any meaningful data out of tcpdump
, I need elevated permissions. To keep this command portable, that means running sudo tcpdump
inside my deno program. How can I set up deno permissions to run a specific command executed through sudo
? A simple permission of --allow-run=sudo
would be dangerous. I could just let the user approve each time, but even then, all they know is that they are approving sudo
, there is no other knowledge of what the subcommand is:
Im not sure if I have a suggestion yet on how we could improve this. Right now I am just curious if anyone else has ran into this. I could leverage roles & permissions on my linux machine to allow this program to run without sudo, but thats not very portable, other users would have to do the same "add user/allow user access to x,y,z/change user to run the command/etc"2 replies
eval script with stricter permissions in deno
Hi all, I wanted to know if its possible to eval a script in deno with more strict permissions. Something like
vm.runInNewContext
in node. At best, I think I can use Deno.Command('deno', {args: ['run', 'user-script.ts']})
right now. However, that means allowing any deno process to be ran at any time from the parent script. I am wondering if there is any way to specifically run a script with a subset of the permissions allowed to the parent script1 replies
how to hash very large files
We have deprecated the old std/hash code in favor of the crypto module, but I do not know what the standard approach to hashing something piecemeal looks like. The advice around the crypto digest generally looks like this:
this works fine on smaller files, but I need to occasionally hash a big file, like 2GB files. This is a lot of data to hold in memory, and if I could leverage readable streams that would be ideal. If I need to do that, should I simply feed the
hash_buffer
back into itself, concatenating new data as I go?15 replies
what is import.meta.url on implicit version
I am in an awkward situation where I want to test retrieving the version from the url of my module when no version is specified (e.g.
deno.land/x/sqlite_native
).
Unfortunately, it doesnt appear that there is a good way to test this. I have found the source file in ~/.cache/deno/deps/https/deno.land/
, but editing it gives an error that the hash map doesnt match (which I suppose is there for safety). I also cannot test this locally since the import.meta.url will be the local file. I could publish a version to deno.land/x/ just to log out the import.meta.url, but I would like to avoid this.
Essentially, I am wondering if deno will redirect the url to the latest version, and that version will appear in the import meta. Of course, if there is a better way to get the module version I am all ears. I am hoping to avoid adding a compile step to ci to edit tags to include a version number.3 replies
third party module - edit webhook subdirectory
Hi, I just published a module https://deno.land/x/sqlite_native@0.1.0 but the actual library content is under the
src/
folder. I did not specify this when first creating the webhook (leading to all imports looking like src/mod.ts
. Is it possible to edit the webhook after creation? Its hard to tell if so, because there doesnt appear to be any 'owner' controls on a module after publishing.2 replies
deno.lock multiple entry point best practices
Hi, I just upgraded to 1.28.0 and realized that lock files are here by default for deno.json config projects. I figure that means its time I adopted lock files. So I wanted to open a forum about best practices. I have read this doc https://deno.land/manual@v1.28.0/basics/modules/integrity_checking, which is a good start. I know at least that a lock file should be checked into git (which is less confusing than w/ node, where lock files change per OS and their advice on version control is pretty fuzzy.
Here is my remaining question though, what happens when I have multiple entrypoints? Specifically, I am looking at this repo I own https://github.com/andykais/sqlite-native. I have three main module entrypoints:
1. src/mod.ts (this is what lib users will use)
2. test/*.ts (this is for running tests)
3. deps/compile.ts (this is a build script for building/upgrading the sqlite.so shared lib)
should I have three separate lock files?
Interestingly, it seems like deno is smart enough to only add to the lock file if I do not specify manual locations (I would assume different entrypoints would cause the deno.lock file to thrash in version control. What is the best practice here, specify multiple entrypoints, or just let deno manage one lock file?
Another, related question, does the lock file do anything as a remote module, or is it only used locally? The docs seem to imply the latter, but I was hoping someone here could confirm.
2 replies
how to cli run node modules without --compat
So
deno run --compat
has now been removed in favor of npm:
specifiers https://deno.com/blog/v1.26#--compat-mode-removed. I am sure this consolidates a lot of code, but I am unsure how I can gain back certain functionality. For instance, I could run a solidjs template out of the box from deno with compat like so:
deno run --compat --unstable --allow-env --allow-read --allow-run --allow-net node_modules/.bin/vite dev
Using npm specifiers, I dont seem to have the same capabilities.
deno run --compat --unstable --allow-env --allow-read --allow-run npm:vite
this most likely has to do with a subprocess with esbuild or something similar, but just in general, it seems like we lost some functionality here4 replies