Blog

How Glide checks a file block by block while it travels

Glide moves a file from one device to another by scanning a code, with no upload in between. Under the hood, it splits the file into blocks based on its own content and checks every block as it arrives. If a block arrives damaged, Glide fetches just that block again. Here's how it works, and where browser limits get in the way.

Engineering6 min read

Fig. 0256 KiB the size of an average block

Moving a file between two of your own devices should be simple. With Glide, you open a page on one device, scan the code with the other, and the file goes straight across. No cable, no account on the second device, and no upload to wait for. Here's what happens between that scan and the file landing, and how the receiving device knows what it wrote matches what you sent.

The short version: Glide splits the file into blocks, gives each block a fingerprint, and checks every one the moment it lands. The longer version is worth reading because of browser limits. Those limits shaped the design more than anything else.

Where does the file actually go?

From one browser straight to the other. Nemi's server introduces the two devices when you scan the code, and then steps out of the way.

Glide reads the file from the sending device a little at a time and writes it to the receiving device as it arrives. That's why a live transfer has no size limit: there's no server in the middle for the file to outgrow.

Some networks block direct connections between devices. When that happens, a relay passes the traffic along. It forwards encrypted data it can't read and doesn't keep. Either way, the browsers encrypt the connection themselves.

Why cut a file into blocks at all?

Because a check at the very end fails too late. The simplest way to send a file is as one long stream in 16 KiB pieces, with a single fingerprint checked after the last piece lands. Glide still does that with older devices that don't speak the block protocol, and it works. The catch is that if one piece gets damaged in transit, the receiver only finds out the whole file is bad after all of it has been sent.

Instead, before the first byte moves, the sender walks the file and splits it into blocks. Each block is at least 64 KiB and at most 1 MiB, averaging 256 KiB (about 4,096 blocks per gigabyte). Each block gets a BLAKE3 hash as its fingerprint, and that list goes to the receiver first. From that point on, the receiver knows what every part of the file should look like before it receives any of it.

One damaged block costs one block

Seven blocks of different sizes, because the content chose the cuts. Six matched their fingerprints on arrival. The darker one didn't, so Glide asks for just that block again.

A drawing, not a measurement. The widths are made up; the rule is the engine's.

Why does the content decide where the cuts fall?

The obvious approach is to cut every fixed number of bytes. The problem is that those cuts depend on position, not content. Add a single byte to the start of a file, and every block after it shifts.

Glide cuts by content instead. It slides over the bytes and cuts wherever a pattern in the data itself triggers a boundary. That way, the same stretch of data produces the same blocks wherever it appears.

That pays off right away inside a single transfer. If two files share a long section, or one file repeats itself, they produce blocks with the same fingerprint. If the receiver already has a block, Glide doesn't send it a second time. The receiver just writes it in both places from the one copy.

Who decides what is sent next?

The receiver does. Because it holds the block list, it asks for blocks by number, 32 at a time, and the sender answers.

As each block arrives, the receiver hashes it and checks it against the list. A match is written to disk. A mismatch is discarded and requested again, without touching anything already written. If a single block arrives damaged 3 times, the transfer stops with an error: by then, something is wrong that retrying won't fix.

A file that finishes is a file where every single block was verified on the way in.

256 KiB

the average block

1 MiB

the largest a block can be

32

blocks asked for at a time

3

tries for one block before giving up

What does a browser stop it from doing?

Two things, and both are worth being upfront about. First, a browser writes a download sequentially from start to finish and can't jump around inside it. So the receiver asks for blocks in file order. The few blocks that arrive early wait in memory (at most 64 MiB) until the earlier ones land.

Second, a browser can't read back a download it has partly written. That rules out resuming an interrupted transfer, because the receiver has nothing to compare against when you restart. A damaged block gets repaired while the connection stays up, but a dropped connection means starting over. A native desktop app doesn't have either limit, which is the other half of this story.

What if one device doesn't know the new way?

Nothing breaks. Every batch of files starts with an offer: the sender says it can send in blocks, and the receiver either accepts or replies the old way. A plain reply falls back to the plain stream with one fingerprint at the end. Neither device needs to be up to date for a transfer to work, and nobody has to pick a mode.

If you've never tried it: open Glide, choose to send from this device, drop your files, and scan the code with the other device. The full steps are in moving a file between two devices. Identifiers like BLAKE3 are public algorithm names, and the numbers here are the engine's own constants.

Questions people ask

How does Glide know a file arrived intact?

Before any bytes move, the sender lists every block in the file along with its fingerprint. The receiver hashes each block as it arrives and compares the two. If a block doesn't match, it's discarded and requested again, so a finished file has had every block verified.

Does a file sent with Glide pass through Nemi's servers?

No. The two browsers connect directly and the file travels between them. Nemi's server only introduces the two devices. If a network blocks a direct connection, a relay forwards the encrypted traffic. It can't read the data and doesn't store it.

What is content defined chunking?

It's a way of splitting a file into blocks where patterns in the data decide each cut, rather than a fixed byte count. The same stretch of data gets cut the same way wherever it appears, so identical blocks can be spotted and sent only once.

Can Glide resume a transfer that was interrupted?

Not in a browser. A browser can't read back a download it has partly written, so there's nothing to compare against when you try again. A damaged block is resent while the connection stays up, but a dropped transfer has to start over.

Is there a size limit on a Glide transfer?

There's no size limit on a live transfer between two devices, because the file never sits on a server. Glide reads it from the sending device a little at a time and writes it to the receiving one as it arrives, keeping memory use low at any file size.

Where the numbers come from

  • The Glide engine: block sizes, request window, retriesglide-web/src/lib.rs
  • The largest block and the block encryptiongithub.com/GuusLab/Glide, crates/glide-core
  • The engine against the native program, both directionsglide-web/tests/interop.rs
  • How a transfer chooses between the two ways of sendinglib/glide/transfer.ts
  • The stream every version understands, and its chunk sizelib/glide/protocol.ts
  • Where the browser writes a downloadlib/glide/storage.ts, public/glide-download-sw.js

Use the thing we write about.

Files, docs, sheets, mail, photos, calendar and meetings in one account, built the way this post describes. Nemi is opening in groups: put your name down and we tell you when yours is up.

15 GB free when you get in. No card needed.