Skip to content

Commit

Permalink
Merge branch 'jviotti-fix/8to16-require'
Browse files Browse the repository at this point in the history
  • Loading branch information
natevw committed Dec 11, 2015
2 parents 3db5606 + 403b0a7 commit 557832c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,30 +264,26 @@ dir.addFile = function (vol, dirChain, entryInfo, opts, cb) {
_name: name
});
if (1 || mainEntry.Name._lossy) { // HACK: always write long names until `._lossy` is more useful!
// name entries should be 0x0000-terminated and 0xFFFF-filled
var workaroundTessel427 = ('\uFFFF'.length !== 1);
if (workaroundTessel427) throw Error("Your JS runtime does not have proper Unicode string support. (If Tessel, is your firmware up-to-date?)");

// name entries should be 0x0000-terminated and 0xFFFF-filled
var S_lde_f = S.longDirEntry.fields,
ENTRY_CHUNK_LEN = (S_lde_f.Name1.size + S_lde_f.Name2.size + S_lde_f.Name3.size)/2,
paddedName = (workaroundTessel427) ? require('struct-fu/8to16').fixString(name) : name,
partialLen = paddedName.length % ENTRY_CHUNK_LEN,
partialLen = name.length % ENTRY_CHUNK_LEN,
paddingNeeded = partialLen && (ENTRY_CHUNK_LEN - partialLen);
if (workaroundTessel427) {
if (paddingNeeded--) paddedName.push(0);
while (paddingNeeded-- > 0) paddedName.push(0xFFFF);
} else {
if (paddingNeeded--) paddedName += '\u0000';
while (paddingNeeded-- > 0) paddedName += '\uFFFF';
}
if (paddingNeeded--) name += '\u0000';
while (paddingNeeded-- > 0) name += '\uFFFF';
// now fill in as many entries as it takes
var off = 0,
ord = 1;
while (off < paddedName.length) entries.push({
while (off < name.length) entries.push({
Ord: ord++,
Name1: paddedName.slice(off, off+=S_lde_f.Name1.size/2),
Name1: name.slice(off, off+=S_lde_f.Name1.size/2),
Attr_raw: S.longDirFlag,
Chksum: null,
Name2: paddedName.slice(off, off+=S_lde_f.Name2.size/2),
Name3: paddedName.slice(off, off+=S_lde_f.Name3.size/2)
Name2: name.slice(off, off+=S_lde_f.Name2.size/2),
Name3: name.slice(off, off+=S_lde_f.Name3.size/2)
});
entries[entries.length - 1].Ord |= S.lastLongFlag;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fatfs",
"version": "0.10.3",
"version": "0.10.4",
"description": "fs implementation on top of raw FAT16/FAT32 block source",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 557832c

Please sign in to comment.