-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Custom Styles feature is broken (#7067)
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
- Loading branch information
Alexander Matyushentsev
committed
Aug 24, 2021
1 parent
a894d4b
commit 1d3d03f
Showing
13 changed files
with
133 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io | ||
|
||
import ( | ||
"io" | ||
"io/fs" | ||
) | ||
|
||
func NewByteReadSeeker(data []byte) *byteReadSeeker { | ||
return &byteReadSeeker{data: data} | ||
} | ||
|
||
type byteReadSeeker struct { | ||
data []byte | ||
offset int64 | ||
} | ||
|
||
func (f byteReadSeeker) Read(b []byte) (int, error) { | ||
if f.offset >= int64(len(f.data)) { | ||
return 0, io.EOF | ||
} | ||
n := copy(b, f.data[f.offset:]) | ||
f.offset += int64(n) | ||
return n, nil | ||
} | ||
|
||
func (f byteReadSeeker) Seek(offset int64, whence int) (int64, error) { | ||
switch whence { | ||
case 1: | ||
offset += f.offset | ||
case 2: | ||
offset += int64(len(f.data)) | ||
} | ||
if offset < 0 || offset > int64(len(f.data)) { | ||
return 0, &fs.PathError{Op: "seek", Err: fs.ErrInvalid} | ||
} | ||
f.offset = offset | ||
return offset, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io | ||
|
||
import "io/fs" | ||
|
||
type composableFS struct { | ||
innerFS []fs.FS | ||
} | ||
|
||
// NewComposableFS creates files system that attempts reading file from multiple wrapped file systems | ||
func NewComposableFS(innerFS ...fs.FS) *composableFS { | ||
return &composableFS{innerFS: innerFS} | ||
} | ||
|
||
// Open attempts open file in wrapped file systems and returns first successful | ||
func (c composableFS) Open(name string) (f fs.File, err error) { | ||
for i := range c.innerFS { | ||
f, err = c.innerFS[i].Open(name) | ||
if err == nil { | ||
break | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io | ||
|
||
import ( | ||
"io/fs" | ||
"path/filepath" | ||
) | ||
|
||
type subDirFs struct { | ||
dir string | ||
fs fs.FS | ||
} | ||
|
||
func (s subDirFs) Open(name string) (fs.File, error) { | ||
return s.fs.Open(filepath.Join(s.dir, name)) | ||
} | ||
|
||
// NewSubDirFS returns file system that represents sub-directory in a wrapped file system | ||
func NewSubDirFS(dir string, fs fs.FS) *subDirFs { | ||
return &subDirFs{dir: dir, fs: fs} | ||
} |