Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`FileSystem.FileHandle.writeFromOffset` ignores its offset and writes at position 0

Chiusa Adatta ai principianti
#63 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript

Direzione di ricerca

Inizia dal punto di ingresso Gren.Kernel.FileSystem.writeFromOffset e confronta la gestione dei suoi argomenti con l’implementazione adiacente di readFromOffset. Esegui prima il ./run.sh della riproduzione; è completato quando la scrittura di due byte all’offset 5 produce AAAAAZZAAA invece di ZZAAAAAAAA.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Found against:* gren 0.6.6, gren-lang/core 7.4.2, gren-lang/node 6.1.3, node 22
Reproduction: in https://github.com/gilramir/gren-bug-reports in 2026-09-11-writefromoffset; ./run.sh prints the figure below.

Reproduction

Write ten As, open the file for writing, put two Zs at offset 5, read it
back:

FileSystem.writeFile fsPermission (Bytes.fromString "AAAAAAAAAA") path
    |> Task.andThen
        (\_ -> FileHandle.openForWrite fsPermission FileHandle.ExpectExisting path)
    |> Task.andThen
        (\fh ->
            FileHandle.writeFromOffset fh 5 (Bytes.fromString "ZZ")
                |> Task.andThen (\_ -> FileHandle.close fh)
        )
    |> Task.andThen (\_ -> FileSystem.readFile fsPermission path)
wrote "ZZ" at offset 5 into "AAAAAAAAAA"
  expected  AAAAAZZAAA
  got       ZZAAAAAAAA

The "ZZ"'s were written at offset 0.

Reason

writeFromOffset takes the offset as a plain Int:

{-| Write bytes into a specific location of a file.
-}
writeFromOffset : WriteableFileHandle a -> Int -> Bytes -> Task FileSystem.Error (WriteableFileHandle a)
writeFromOffset =                                                     
    Gren.Kernel.FileSystem.writeFromOffset

The kernel function behind it reads that argument as a record:

var _FileSystem_writeFromOffset = F3(function (fh, options, bytes) {
  return __Scheduler_binding(function (callback) {               
    _FileSystem_writeHelper(
      fh,
      bytes,
      0,                                
      bytes.byteLength,
      options.__$offset,
      callback,
    );
  }); 
});

options is a number, so options.__$offset is undefined. That is handed to
fs.write as its position, where undefined means "wherever the file
currently is" — which for a freshly opened handle is 0.

So the offset argument has no effect at all. Every writeFromOffset writes
where write would have written.

readFromOffset beside it does take a record, { offset, length }, and is
correct. The kernel function for the write looks like a copy of the read's that
kept the record access after the Gren signature stopped passing one.

Lingua principale
JavaScript
Stelle
13
Fork
6
Merge medio
4g 10h
PR unite (30g)
4

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di gren-lang/node

Tutte le issue di gren-lang/node

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.