Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Cheen
Apr 17, 2005

Yarn's benefits are minor: workspaces (want to make a monorepo?) and package dependency support.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
what is this dev.to site is it just medium for even bigger dorks?

necrotic
Aug 2, 2005
I owe my brother big time for this!
Yes

stoops
Jun 11, 2001
I have a table with many rows. i want to be able to input a row number and it grabs that row and moves it a couple of rows to the top or bottom.

I'm not clicking on the row itself; I would like to enter a rownumber and the number of spaces to the top or bottom and then the row moves.

I know how to make input boxes and use javascript to grab the value, but i'm not understanding how to use that number to select the row and move it.

There are so many ways to grab the table row that i'm not sure which is correct

Any help is appreciated.

LifeLynx
Feb 27, 2001

Dang so this is like looking over his shoulder in real-time
Grimey Drawer
Edit: Nevermind

Volguus
Mar 3, 2009

stoops posted:

I have a table with many rows. i want to be able to input a row number and it grabs that row and moves it a couple of rows to the top or bottom.

I'm not clicking on the row itself; I would like to enter a rownumber and the number of spaces to the top or bottom and then the row moves.

I know how to make input boxes and use javascript to grab the value, but i'm not understanding how to use that number to select the row and move it.

There are so many ways to grab the table row that i'm not sure which is correct

Any help is appreciated.

code:
element = document.getElementById("#that_tbody_id");
row = element.children[5];
https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children

Of course, this is just one possible idea. There are other ways to skin this cat.

Jazerus
May 24, 2011


Volguus posted:

code:
element = document.getElementById("#that_tbody_id");
row = element.children[5];
https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children

Of course, this is just one possible idea. There are other ways to skin this cat.

1. you don't use a # in the string if you're using getElementById, as it's implicitly an ID
2. children is a read-only live collection, which might or might not lead to some weirdness compared to grabbing a static nodelist if other things are happening on the page. why chance it?
code:
//let's assume you already got your input box values and stored them in the variables, rowNumber and spaces
//i'm assuming your row numbers as input by the user start at 0, if they start at 1 subtract 1 from rowNumber before you start using it
const tbody = document.querySelector('#that_tbody_id')
const rows = Array.from(document.querySelectorAll('#that_tbody_id tr'))

rows.forEach((row) => {
  row.remove()
})

rows.splice(spaces, 0, rows[rowNumber])
rows.splice(rowNumber+1, 1)

rows.forEach((row) => {
  tbody.append(row)
})
this will grab your desired row and move it the specified number of spaces from the top. you will need to reverse the index calculations on the splice calls to insert from the bottom instead when you want to do that.

edit: oh poo poo well i just realized re-reading the original post and you probably wanted to just move it up or down the specified number of spaces, huh. not make it appear that number of spaces from the top. fortunately you just have to change the first splice call to
code:
rows.splice(rowNumber - spaces, 0, rows[rowNumber])
to get that behavior. again, that one goes up, you'll have to do rowNumber + spaces to go down.

Jazerus fucked around with this message at 03:51 on Jan 28, 2020

Volguus
Mar 3, 2009
This is good. Ugly as hell, but good.

Jazerus
May 24, 2011


Volguus posted:

This is good. Ugly as hell, but good.

yeah i'm assuming they don't need this for any kind of fancy or job-related purpose. please do not put my code into production.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Jazerus posted:

yeah i'm assuming they don't need this for any kind of fancy or job-related purpose. please do not put my code into production.

It's already powering 12,874 e-commerce sites.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Volguus posted:

This is good. Ugly as hell, but good.

New thread title IMO

asap-salafi
May 5, 2012

THUNDERDOME LOSER 2019

Lumpy posted:

It's already powering 12,874 e-commerce sites.

New thread title

tankadillo
Aug 15, 2006

Lumpy posted:

It's already powering 12,874 e-commerce sites.

It needs its own GitHub repo with 50 releases that each just update the Prettier/ESLint rules and a dozen open issues arguing about the tests and the code of conduct.

Polio Vax Scene
Apr 5, 2009



Volguus posted:

This is good. Ugly as hell, but good.

Lumpy posted:

It's already powering 12,874 e-commerce sites.

Jazerus posted:

please do not put my code into production.

Honestly all three of these are great

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Removing all the rows, reordering them, and then adding them back seems unnecessary, doesn't it? Why not just take the row in question and use insertBefore to move it in it's new location?

Something like this SO answer:
https://stackoverflow.com/questions/39038113/javascript-insert-row-into-table-after-row-with-certain-id

Edit:

Jazerus posted:

2. children is a read-only live collection, which might or might not lead to some weirdness compared to grabbing a static nodelist if other things are happening on the page. why chance it?

What's the concern here? Children is live, but there won't be anything else editing the DOM while you're in your function moving the row (unless there's some sort of iframe fuckery?)

HappyHippo fucked around with this message at 17:11 on Jan 28, 2020

Jazerus
May 24, 2011


honestly? i forgot that insertBefore and before existed. that's a much more efficient way to do it.

using children is probably fine too, I tend to just avoid the live collections in the DOM unless they're obviously the best choice

Jazerus fucked around with this message at 23:30 on Jan 28, 2020

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
i have a helper function i use for this https://github.com/magcius/noclip.website/blob/master/src/ui.ts#L55-L80

stoops
Jun 11, 2001
I appreciate everyone's replies. I actually learned a lot from your posts and links.

I ended up going with something like this:

code:
function addRowAfter(row,moveTo){
    var myRow = document.getElementById('row-' + row);
    var refElement = document.getElementById('row-' + moveTo); 
    refElement.parentNode.insertBefore(myRow, refElement.previousSibling );
}
addRowAfter(row,moveTo);

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Date / Time library recommendation time! We were using Spacetime, which works great... except for the fact that it fails one of the most important requirements we have: displaying DST / timezone "correct" times to users. Spacetime only properly handles a single year, and fudges it for the rest, which is a decent trade-off, and works for most people I guess.

That said, we now need to replace Spacetime with something before March 8, so who is using something that doesn't suck* for dates and times? Our single big requirement is handling DST boundaries and timezones. This spacetime example is effectively what we need:

JavaScript code:
const dstStart2019 = "2019-03-10T12:00:00";  // noon the first day of DST
const _dstStart = spacetime(dstStart2019, "America/Chicago);  // noon in Chicago to be exact
// make sure we are in Chicago and in DST (-5)...
expect(_dstStart.format("iso")).toBe("2019-03-10T12:00:00.000-05:00")

// subtract a day, which passes over the DST boundary
const _backFromStart = _dstStart.subtract(1, "day");
// see if spacetime handled the DST change properly
expect(_backFromStart.format("iso")).toBe("2019-03-09T12:00:00.000-06:00");
The above works only for 2019 in spacetime 6.3, and fails in 6.4 which supports the 2020 DST dates.

Being "fast" is also good, as we render the converted timezone times in graph tooltips, but obviously "fast" is subjective and may not be any bottleneck at all.

reversefungi
Nov 27, 2003

Master of the high hat!
Does anyone know why a call using "withCredentials" is failing on one specific machine?

We have some code that looks like this
JavaScript code:
const response = await axios.get(authEndpoint, { withCredentials: true })
By the time they've hit this logic, the user has already authenticated and hitting this auth endpoint returns their token, credentials, etc. This works for everyone as far as I know.

We recently had one person who is getting 401 errors, which happens when you omit withCredentials, so that the user's cookie information isn't passed on, and the authEndpoint registers them as logged out, like if you had opened the endpoint in an incognito window or something. If they manually hit the authEndpoint, they're able to get their token/credentials, and not see a 401 error. If they try to access that endpoint programmatically in any way (I had them copy and paste a similar request to the authEndpoint using XmlHTTPRequest + withCredentials), the endpoint doesn't pickup the credentials and returns a 401. This is happening across multiple browsers for the user, and they are on the same network as the rest of us, so it can't be a network issue. If they use their phone, they are able to access the site fine and the request to the authEndpoint goes through, which leads me to think there's something funky going on with their machine.

Does anyone know what could possibly be causing this? Is there some sort of weird IT setting to prevent XSS or something that doesn't allow cookies to be sent through?

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Lumpy posted:

Date / Time library recommendation time! We were using Spacetime, which works great... except for the fact that it fails one of the most important requirements we have: displaying DST / timezone "correct" times to users. Spacetime only properly handles a single year, and fudges it for the rest, which is a decent trade-off, and works for most people I guess.

That said, we now need to replace Spacetime with something before March 8, so who is using something that doesn't suck* for dates and times? Our single big requirement is handling DST boundaries and timezones. This spacetime example is effectively what we need:
How about Luxon? I created a JS Fiddle here showing it passing the tests you posted: https://jsfiddle.net/v8oszk7f/12/

I like Luxon because it uses the browser's Intl library for timezone support, which means it's also on the smaller side compared to MomentJS with its timezone support. Luxon should work in most modern browsers and Node, if MDN is to be believed.

minato
Jun 7, 2004

cutty cain't hang, say 7-up.
Taco Defender

The Dark Wind posted:

Does anyone know why a call using "withCredentials" is failing on one specific machine?
Sounds like it could be a CORS problem. See if you can get them to do a network trace and see if the creds are actually getting sent, because "for security reasons" simple requests will just straight up return an empty response with no errors if the server is denying them due to CORS issues.

stoops
Jun 11, 2001
I'm using this library to upload files via ajax:
https://github.com/blueimp/jQuery-File-Upload

It works fine, but I'm noticing that it's turning my periods into hyphens (it doesn't turn the period extension).

so, for example,

mwr_PJ13456789_m08.1_2.7x2.00.atm.txt

becomes

mwr_PJ13456789_m08-1_2-7x2-00-atm.txt

I think the blueimp libary is doing this, but i'm not sure a way around it besides converting the hyphens back to periods, which may make it harder if a file already has hyphens alongside periods.

Is there a security reason or something that it would force the periods into hyphens?

smackfu
Jun 7, 2004

The Dark Wind posted:

Does anyone know what could possibly be causing this? Is there some sort of weird IT setting to prevent XSS or something that doesn't allow cookies to be sent through?
We had a similar issue caused by an ad blocker. Despite the user denying they were using one.

Shaman Tank Spec
Dec 26, 2003

*blep*



I'm having a weird problem.

I'm running a website that uses NodeJS with an ExpressJS backend, and communicating through SocketIO.

When the user logs in, the login function creates a unique session ID and stores both that and the logged in user's name (which the site requires for really dumb legacy reasons that are not my fault) in sessionStorage, simply with window.sessionStorage.setItem('token', tokenValue) and window.sessionStorage.setItem('username', username). That works fine. The keys get set, and using Chrome's dev tools I can see that they are in my sessionStorage just fine.

However, when I load any other page on the website, the token key in sessionStorage becomes undefined. The username key persists through page changes and reloads. Both keys are retrieved using window.sessionStorage.getItem(), but for one thing that shouldn't set the value of a key to undefined, and even if it did, the username value remains set.

Can anyone think of anything that might be causing this?

E: never mind, I figured it out. The problem is this loving hellscape of a mess of socketIO calls with identical names but different implementations flying out of various classes back and forth. I want to strangle the guy who made this website originally.

Shaman Tank Spec fucked around with this message at 15:57 on Feb 12, 2020

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Something approaching 100% of Dev time is spent on the "why the heck was this built like that"problem. The longer I'm in the industry especially around web development the more pronounced this problem is. I'm less and less able to imagine the vast sums of money companies could save by just hiring good devs as opposed to thousands of bad ones constantly.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Nolgthorn posted:

Something approaching 100% of Dev time is spent on the "why the heck was this built like that"problem. The longer I'm in the industry especially around web development the more pronounced this problem is. I'm less and less able to imagine the vast sums of money companies could save by just hiring good devs as opposed to thousands of bad ones constantly.

Good devs want more money than bad devs, and you gotta keep budget down so you get a bonus. Plus, good devs always seem to want to take slightly longer than bad devs to finish the first version of something, which doesn't make any sense. If they were good, they'd be faster, right?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I've worked at several shops that had too many devs and very little was getting done because everyone was being careful not to knock over the house of cards. It wasn't a particularly complex project. Two good devs could have re written the entire thing from scratch in a couple of months, but that would have cut into the push for more features so I understand why they couldn't do it.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Nolgthorn posted:

The longer I'm in the industry especially around web development the more pronounced this problem is.

This is because you're better able to see the problems the more experienced you are.

It's particularly prevalent in web development because The Webs are most often the interface between a business and it's customers and thus there are more stakeholders who don't have the technical background to understand the costs of implementing Feature X rather than spending a month on refactoring or whatever else...from the CEO to marketing.

On the other hand, adding features may be what allows the business to survive. Developers are often kind of siloed off from having to worry about any of this boring stuff that makes a business survive.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It demonstrates though that nobody really has to be very good or get a lot done in order to succeed in the industry.

As evidenced by the slow pace of development in many of these shops being apparently remedied by hiring more developers. A business would be able to get a lot more done a lot faster, including the implementation of new features if it were possible to cut down on developers dramatically and focus on the architecture of the software first and foremost. Isn't that true? And if so why aren't there any mechanisms in place even to this day that address it?

Companies will spend loads of money hiring experts in things like Agile methodologies. So why not software architects? Is it a lack of skilled developers in management roles?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Nolgthorn posted:

It demonstrates though that nobody really has to be very good or get a lot done in order to succeed in the industry.

Yes, us software developers tend to over-value what we do...just like everyone.

Nolgthorn posted:

As evidenced by the slow pace of development in many of these shops being apparently remedied by hiring more developers. A business would be able to get a lot more done a lot faster, including the implementation of new features if it were possible to cut down on developers dramatically and focus on the architecture of the software first and foremost. Isn't that true? And if so why aren't there any mechanisms in place even to this day that address it?

Companies will spend loads of money hiring experts in things like Agile methodologies. So why not software architects? Is it a lack of skilled developers in management roles?

At the risk of over-valuing what we do...I think a lot of it is that it's hard to communicate what we do to non-developers. The best we can often do is flawed analogies.

A good test of this would be if technology companies that promote engineers from within to executive roles are better able to dedicate time to writing tests, building good foundations, refactoring, etc. All the stuff that doesn't seem to directly "add value".

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Thermopyle posted:

On the other hand, adding features may be what allows the business to survive.

True, but it doesn't have to be an either/or thing.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Thermopyle posted:

On the other hand, adding features may be what allows the business to survive.
There's also the thing where the designers and managers who pushed that feature will always push that story, but we don't actually have insight into a parallel universe where that feature wasn't added, so we don't actually ever know if a business did better or worse because of adding a feature (unless that feature is something unusually measurable like specifically monetization of a previously unmonetized product or something).

I suppose it's also possible that lovely bugs that should have been caught by tests sometimes benefits a business, but that seems less likely than a new feature being detrimental.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

roomforthetuna posted:

There's also the thing where the designers and managers who pushed that feature will always push that story, but we don't actually have insight into a parallel universe where that feature wasn't added, so we don't actually ever know if a business did better or worse because of adding a feature (unless that feature is something unusually measurable like specifically monetization of a previously unmonetized product or something).

I suppose it's also possible that lovely bugs that should have been caught by tests sometimes benefits a business, but that seems less likely than a new feature being detrimental.

A/B testing can be used to test features, whether by making the feature a component of the view that just doesn't get included sometime, or using feature flags. It's already used to check engagement with say, different layouts on a page, but nothing's stopping you from a/b testing features as well. Serve half the users with feature enabled, half with feature disabled, and check metrics like how long people stay on the page, page load performance, average cart value etc. Granted if what you're working on isn't very web-like or e-commerce-like (despite using js), or you don't have a significant number of users, or if you don't have metrics on what would make your application useful, then the technique won't work - but then that also indicates you have bigger problems than quantifying what features are useful.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

roomforthetuna posted:

There's also the thing where the designers and managers who pushed that feature will always push that story, but we don't actually have insight into a parallel universe where that feature wasn't added, so we don't actually ever know if a business did better or worse because of adding a feature (unless that feature is something unusually measurable like specifically monetization of a previously unmonetized product or something).

I suppose it's also possible that lovely bugs that should have been caught by tests sometimes benefits a business, but that seems less likely than a new feature being detrimental.

As is usually the case, the actual evidence for or against doesn't really matter. What matters is what the stakeholders believe is the case.

Part of the thing that some people believe is that it's often not any single issue that makes or breaks a business, it's a culture of continual feature adding that causes potential new customers to hear about your product and what to use it.

It's not usually an explicit belief, but just a general feature of how they feel about the product should be "progressing".

Also, as BF mentions people measure new features all the time with A/B testing or just comparing traffic/signups/income/whatever pre/post new feature introduction.

That second method is more fraught and hard to do correctly, but most people aren't really interested in reality, they're just interested in confirming things they already believe!

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Thermopyle posted:

That second method is more fraught and hard to do correctly, but most people aren't really interested in reality, they're just interested in confirming things they already believe!
Yeah, a lot of the A/B testing metrics aren't measuring what they think they are. Like is more engagement/more clicks actually a good thing? Not if your app has turned one page with all the information into three pages you have to click between, you've actually just increased user frustration, but it looks good in the engagement metrics. Made 25% more ad money? Great! Except not so much if you also convinced half your users to never come back because the experience sucked now.

(And the eponymous app thing, where annoying notifications inevitably measurably increase usage in the short term, and you don't have access to metrics on "number of people who blocked all notifications from your app forever" so you don't get to measure the downside.)

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

roomforthetuna posted:

Yeah, a lot of the A/B testing metrics aren't measuring what they think they are. Like is more engagement/more clicks actually a good thing? Not if your app has turned one page with all the information into three pages you have to click between, you've actually just increased user frustration, but it looks good in the engagement metrics. Made 25% more ad money? Great! Except not so much if you also convinced half your users to never come back because the experience sucked now.

(And the eponymous app thing, where annoying notifications inevitably measurably increase usage in the short term, and you don't have access to metrics on "number of people who blocked all notifications from your app forever" so you don't get to measure the downside.)

The big problem with feature development is that you may not necessarily be able to trust users or stakeholders in determining what features are useful. When Microsoft started instrumenting applications such as Word with metrics on whether or not a feature is used or not, it found that the vast majority of features in its applications go nearly completely unused. Customers will often request features and not use them at all. Everyone hates bloated software, but when you hire people such as product owners and stakeowners and their job is to come up with features, you can run into the situation where everyone involved is bloating the product - engineering wants to work for a living, the product owners add more features because it's very easy to look at a spreadsheet and be like "I designed and requested x y and z feature," and marketing likes to have data sheets indicating that they have more features than the competitor. This can lead to a situation where the product becomes bloated - development and testing time starts taking much longer for the features that actually matter as so much effort needs to be devoted to features that are ultimately irrelevant. While it's true that A/B test metrics may not necessarily in and of themselves reflect the value of the feature, developing metrics for determining whether a feature is useful and/or adds value is of paramount performance, as oftentimes, a product can be just "good enough" without needing an entire team of people to gently caress with it and make it worse over the course of years - let those people work on new projects and develop new business.

Bruegels Fuckbooks fucked around with this message at 05:24 on Feb 27, 2020

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Bruegels Fuckbooks posted:

I guess, but the big problem with feature development is that you may not necessarily be able to trust users or stakeholders in determining what features are useful. When Microsoft started instrumenting applications such as Word with metrics on whether or not a feature is used or not, it found that the vast majority of features in its applications go nearly completely unused. Customers will often request features and even not use them at all. Everyone hates bloated software, but when you hire people such as product owners and stakeowners and their job is to come up with features, you can run into the situation where everyone involved is bloating the product - engineering wants to work for a living the product owners add more features because it's very easy to look at a spreadsheet and be like "I designed and requested x y and z feature," and marketing likes to have data sheets indicating that they have more features than the competitor. This situation can lead to a situation where the product becomes bloated, development and testing time starts taking much longer for the features that actually matter as so much effort needs to be devoted to features that are ultimately irrelevant. While it's true that the A/B test metrics may not necessarily in and of themselves reflect the value of the feature, developing metrics for determining whether a feature is useful and/or ads value is of paramount performance, as oftentimes, a product can be just "good enough" without needing an entire team of people to gently caress with it and make it worse over the course of years - let those people work on new projects and develop new business.
True. I endorse A/B testing as a rationale for *not* doing a thing. I hate it as a justification for doing a thing. :)

(Though also not always as a reason for not doing a thing - "fewer than 1% of people use emergency ambulance services so we might as well not bother having them!" Sometimes a rarely-used feature is still a good and valuable feature. And sometimes an often-used feature is just used because some fucker shoved it in the way between the startup screen and what I actually want to do.)

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
I'm looking for an acceptable method to compute the SHA-256 hash of a binary file. This is what I've cobbled together :
JavaScript code:
 // Other Vue stuff
		processHash(){
			var vm = this;
			// this is a File object
			var onefile = this.file[0]
			var reader = new FileReader();

			reader.onload = async function(event) {
				var binary = event.target.result;
				const buf = await new Response(binary).arrayBuffer();
				const hash = await crypto.subtle.digest("SHA-256", buf);
				let result = '';
				const view = new DataView(hash);

				for (let i = 0; i < hash.byteLength; i += 4) {
					result += view.getUint32(i).toString(16).padStart(2, '0');
				}

				shash = "0x" + result
				console.log(result)
			};
			reader.readAsArrayBuffer(onefile)
		}
My problem is this the results seem usually off by a digit, when compared to what I get with openssl dgst -sha256 file.pdf:
code:
0x5d16957d32099e88f070b204f4d3cf686d010e25bba28d2d23f169536bb87cf # js result
0x5d16957d32099e88f070b204f4d3cf686d010e25bba28d2d23f1695306bb87cf # openssl result
I've also tried crypto-js which returned identical values for all binary files.

ynohtna posted:

Looks to me like your call to .padStart is wrong.

It's expecting to pad just a single byte at a time, thus the targetLength parameter of 2 hex characters, but the loop it's in is processing 4 bytes (Uint32) at a time so the target length should be 8.

This works with my test files so it will do for now. Thanks !

unpacked robinhood fucked around with this message at 16:13 on Feb 27, 2020

Adbot
ADBOT LOVES YOU

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
Looks to me like your call to .padStart is wrong.

It's expecting to pad just a single byte at a time, thus the targetLength parameter of 2 hex characters, but the loop it's in is processing 4 bytes (Uint32) at a time so the target length should be 8.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply